std::uniform_int_distribution isn't random enough

前端 未结 4 1168
面向向阳花
面向向阳花 2021-01-07 15:16

I want to randomly select an integer among n numbers, where n is small (say 5). To do this, I am using std::uniform_int_distribution.

The exact details

4条回答
  •  春和景丽
    2021-01-07 15:57

    As said, I should seed the generator. Notice that the reference does not provide something obvious for a seed.

    The working code is here.

    Notice, that as mentioned in the answers, mt19937 should be used, for better speed and quality.

    Example in first answer here.

    Here is another example, found on the internet, that compiles.

提交回复
热议问题