Random value from enum with probability

前端 未结 7 967
既然无缘
既然无缘 2020-12-20 21:40

I have an enum that I would like to randomly select a value from, but not truly random. I would like some of the values to be less likely of being selected so far. Here is

相关标签:
7条回答
  • 2020-12-20 22:17

    Assuming you have a finite number of values you could have a separate array (float[] weights;) of weights for each value. These values would be between 0 and 1. When you select a random value also generate another random number between and only select the value if the second generated number is below the weight for that value.

    0 讨论(0)
提交回复
热议问题