Generate random numbers uniformly over an entire range

后端 未结 17 2337
野性不改
野性不改 2020-11-22 04:21

I need to generate random numbers within a specified interval, [max;min].

Also, the random numbers should be uniformly distributed over the interval, not located to

17条回答
  •  难免孤独
    2020-11-22 05:19

    If you are concerned about randomness and not about speed, you should use a secure random number generation method. There are several ways to do this... The easiest one being to use OpenSSL's Random Number Generator.

    You can also write your own using an encryption algorithm (like AES). By picking a seed and an IV and then continuously re-encrypting the output of the encryption function. Using OpenSSL is easier, but less manly.

提交回复
热议问题