Generate random numbers uniformly over an entire range

后端 未结 17 2611
野性不改
野性不改 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 04:56

    I just found this on the Internet. This should work:

    DWORD random = ((min) + rand()/(RAND_MAX + 1.0) * ((max) - (min) + 1));
    

提交回复
热议问题