selection based on percentage weighting

后端 未结 13 2139
忘掉有多难
忘掉有多难 2020-12-04 13:40

I have a set of values, and an associated percentage for each:

a: 70% chance
b: 20% chance
c: 10% chance

I want to select a value (a, b, c) based

13条回答
  •  悲&欢浪女
    2020-12-04 14:00

    I think you can have an array of small objects (I implemented in Java although I know a little bit C# but I am afraid can write wrong code), so you may need to port it yourself. The code in C# will be much smaller with struct, var but I hope you get the idea

    class PercentString {
      double percent;
      String value;
      // Constructor for 2 values
    }
    
    ArrayList list = new ArrayList

提交回复
热议问题