0

Testing if rand is really random

What would be a good algorithm to show whether a list of values (eg returned by rand() ) are random?

25th Dec 2016, 5:27 PM
ifl
ifl - avatar
5 Respuestas
0
yes sure Vladislav. but it does not answer the initial question. So how could we write a program that proves or disproves that the list of numbers returned by rand is likely to be random or not?
25th Dec 2016, 5:37 PM
ifl
ifl - avatar
0
Remove srand() to prove that at each program launching it generates the same sequence And the source of rand https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=stdlib/rand_r.c;hb=HEAD
25th Dec 2016, 5:46 PM
Vladislav
Vladislav - avatar
0
sure... but lets say we keep srand with a reasonable seed. What sort of program would show that the list of values returned by rand are random and not biased in some way?
25th Dec 2016, 5:51 PM
ifl
ifl - avatar
0
Generated values are random for us and we can see no logical sequence. The algorithm uses overflow so.. Yes, it's random Example is in the 1st answer
25th Dec 2016, 6:01 PM
Vladislav
Vladislav - avatar
- 1
rand() is not random. It has seed - the first value, and complex algorithm that produce new value using previous. Some examples //main srand(time(0)); for(int i = 0; i < 1000000; ++i) cout << rand(); srand initialize seed with current time, so the generated sequence is "random" but if you remove srand(), rand() generates always the same list of numbers.
25th Dec 2016, 5:35 PM
Vladislav
Vladislav - avatar