How do PHP and other languages ​​choose random numbers?

I actually studied PHP, so this question only occurred to me. How does a computer pick a random number?

  • What is the logic for generating random numbers?
  • Is the computer used using garbage values ​​for random numbers?
+4
source share
3 answers

Random numbers, which we usually access from code, are called pseudo-random numbers. They are based on mathematical sequences of numbers that are repeated only for a very, very long time. The place to start in the sequence is based on a seed, which is usually taken as a function of time.

The numbers seem random, but in fact it is not, and therefore they are called "pseudo-random".

Further reading: http://en.wikipedia.org/wiki/Random_number_generation

+2
source

Depending on the programming language / script, there are so-called pseudo-random values. Since there is no way on computers to simply select the number that comes to their mind (heh!), There is an algorithm / calculation that creates the number. The principle is very simple. The random value you get is random, because the way you calculate it is not known to you. If you had a randomizer function that worked for some time without changing its seed (the value that you can enter to change the calculation in the background), the values ​​it gives will be repeated.

+1
source

Look at the wiki , they explained it pretty well.

Most random numbers of computers are pseudo-random. If you need truly random numbers, you should use white noise as a source and digitize it.

+1
source

Source: https://habr.com/ru/post/1434298/


All Articles