Generate random numbers uniformly over an entire range

后端 未结 17 2614
野性不改
野性不改 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:05

    Check what RAND_MAX is on your system -- I'm guessing it is only 16 bits, and your range is too big for it.

    Beyond that see this discussion on: Generating Random Integers within a Desired Range and the notes on using (or not) the C rand() function.

提交回复
热议问题