+ 1
Randomization?
How does randomization work? How does a random value get it's value? I couldn't really find anything on the internet about it. For example: rand()%9+1 will generate a random number from 1 to 9 But how does it decide what the value will actually be?
1 ответ
+ 3
The rand function contains a linear equation that is used to retrieve random numbers, based off an initial seed value. This seed is initialized once, and is the first random number. Numbers following the list are generated by operating on the seed in a periodic fashion. The equation is chosen in such a way that repetitions of the generated random numbers are minimum.
For more information: https://stackoverflow.com/questions/3539398/how-does-rand-work-does-it-have-certain-tendencies-is-there-something-better
In C++, there are other pseudorandom generators that use different algorithms. (https://en.cppreference.com/w/cpp/header/random ) rand is a pseudorandom linear congruential generator. These are pseudorandom as it is still possible, with information about seed values and internal constants, to predict the next random number that will be generated by these algorithms.