Generate random numbers uniformly over an entire range

后端 未结 17 2350
野性不改
野性不改 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条回答
  •  旧时难觅i
    2020-11-22 05:03

    You should look at RAND_MAX for your particular compiler/environment. I think you would see these results if rand() is producing a random 16-bit number. (you seem to be assuming it will be a 32-bit number).

    I can't promise this is the answer, but please post your value of RAND_MAX, and a little more detail on your environment.

提交回复
热议问题