I need random algorithm with weighing options

前端 未结 3 393
予麋鹿
予麋鹿 2021-02-02 04:38

I have a requirement in my .NET project where I need to select an item from a collection, each item has a Weight (integer from 1 to 10) assigned to it.

I need a random g

3条回答
  •  长发绾君心
    2021-02-02 04:48

    What you're looking for is called the Weighted Selector algorithm. I actually created an open source C# project for this some time ago!

    It's very easy to use and efficient. Also, the documentation should get you going with no problem.

    Here are a few links:

    • Weighted Selector on Github
    • Weighted Selector nuGet Package

提交回复
热议问题