+ 2
truly and pseudo random number generator
what is the difference between the truly and pseudo random number generator although both of them show same output in several examinations ??
4 Answers
+ 3
The difference is in the source of entropy. Pseudo-random generator is completely deterministic, truly random generator uses some external source of entropy that considered to be physically random.
https://en.wikipedia.org/wiki/Pseudorandom_number_generator
https://en.wikipedia.org/wiki/Random_number_generation#.22True.22_vs._pseudo-random_numbers
What do you mean by "both of them show same output in several examinations"? Which generators did you use?
+ 3
Oh, rand() is a pseudo random generator, it has no true random abilities. As computers are completely deterministic devices, they can't produce anything truly random. So algorithms like rand() uses, just produce a sequence of numbers that seem random. For example, an algorithm like this may be used:
// LinearCongruentialGenerator
int lcg(int seed = 987456321) {
static int s = seed;
static int a = 5432111;
static int c = 8760334;
static int mod = 321456987;
s = (a * s + c) % mod;
return s;
}
The srand() call is used to initially "shuffle" the sequence. It doesn't make rand() truly random. To be truly random, the generator should use some outside source of entropy (randomnes) and redistribute it to the desired range and distribution. For the source of entropy, the generator may survey last n keystrokes or mouse coordinates, measure some physical values like temperature or preasure, or even receive a cosmic radiation.
And here's the documentation on rand() and srand():
http://www.cplusplus.com/reference/cstdlib/rand/
http://www.cplusplus.com/reference/cstdlib/srand/
+ 1
I mean if we use srand function or not , outputs always are similar to each other and just when we use time() function as seed it change in each run
+ 1
thank you so much