R
R
reddyk12019-10-12 22:29:20
PHP
reddyk1, 2019-10-12 22:29:20

Why can rand() produce very close values?

Why rand() sometimes works fine, but sometimes it can produce something like this in a row:
1173
1174
1250
1259
These values ​​were output by the function in 4 days at 0:00
upd.
As of PHP 7.1.0, rand() uses the same random number generation algorithm as mt_rand().
code that is run by cron once a day:
<?php
echo rand(1000,1300);
?>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Aksentiev, 2019-10-12
@Sanasol

https://toster.ru/answer?answer_id=1169362#answers...
Why rand() is bad
boallen.com/random-numbers.html
Real random (or good pseudo random like mt_rand())
Pseudo random
randbitmap_computer.png

F
FanatPHP, 2019-10-13
@FanatPHP

Because random.
Someone here needs to understand for themselves the meaning of this word. And obviously not just one author.
By chance, there may be not only "close" but generally the same values.

S
SagePtr, 2019-10-13
@SagePtr

If you need cryptographically strong random numbers, then use the random_int function (PHP 7+)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question