+ 5
HOW DO RANDOM NUMBER ALGORITHMS WORK???
Since computer stuff are always accurate and always deliver a fixed result, its kind of perplexing how it could be random😕
4 odpowiedzi
+ 5
You are right! Computer are accurate and deliver a fixed result. But a computer can make random results if you give it a ever changing variable. The current time is a very good and ever-changing variable to use as a seed for your randomness needs.
One example is like in C++ there is a rand function that generate a random output. Though the rand function will have the same output every time you run the program, if you have a static seed for the function. But if you set the current time as the seed, the output will be different every time you run the program.
So, basicly to have total randomness in computers you need to have values that are changing.
Hope this helps you!
+ 1
@Microhacker just for clarification. Computer cannot never ever give purely random number. It is always pseudo-random. If the computer would give number out of nothing, just when we ask it deliveres I'd agree that the number is random. But to generare (pseudo) random number we have to chose a seed just as you mentioned and create algorythm, which kinda defeats the point of randomness.
BUT it doesn't mean that PRNG (Pseudo random number generators) are bad, or unuseful. The algorythms they use almost always guarantee different output from last one, which is what we want to achieve.