How random is the rand () function?

In particular, my question is, with infinite time int(rand()*1000), will each number eventually hit from 0 to 999? How about 10 ^ 4, 10 ^ 5 ... I think it is guaranteed to break as soon as you hit the size in memory, i.e. If rand () returns a float, that is, n bits in memory, you cannot press more than n different integers, so as soon as you get to rand()*(2^n+1), you will definitely miss some of them.

+3
source share
1 answer

Yes, given infinite time, it will hit every number in your range if it has an infinite period; as soon as the seed value is reached again, the sequence repeats. Of course, as you mentioned, you would limit the accuracy of the value returned by rand (), and you would end up at the breakpoint where it could not be mapped to every integer in a sufficiently large range. But if you consider a theoretical computer with infinite accuracy and period (you bring up infinity), then you will hit every number in the specified range with infinite time.

, rand() LCG, . , , ( , ). , - Mersenne Twister. Boost, Mersenne Twister, .

0

All Articles