changing probability of getting a random number

前端 未结 7 1518
南方客
南方客 2020-12-09 22:15

I would like to generate a random number between 0 and 3 and I have the following in my code:

int random = rand() % 4;

This works fine but

相关标签:
7条回答
  • 2020-12-09 22:55

    I would just map more values to 1,2,3 from a larger set. For example: 9 and map 1,2,3 => 1, 3,4,5=>2, 6,7,8=>3 and 0 for zero. There are other ways, but I am working within your question

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