Bug #41 RAND() is not returning random enough values for the first run
Submitted: 26 Jan 2003 19:12 Modified: 26 Jan 2003 21:00
Reporter: Peter Zaitsev (Basic Quality Contributor) Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.0 & 3.23 OS:Linux (Linux (All))
Assigned to: CPU Architecture:Any

[26 Jan 2003 19:12] Peter Zaitsev
Description:
MySQL does not return random enough values for the first rand() call after connection is established. It looks like it is not seeded well enough:

How to repeat:
Notice numbers does not seems to have even distribution in the range from 0-1

pz@abyss:~> mysql -u root -e "select round(rand(),2)";
+-----------------+
| round(rand(),2) |
+-----------------+
|            0.40 |
+-----------------+
pz@abyss:~> mysql -u root -e "select round(rand(),2)";
+-----------------+
| round(rand(),2) |
+-----------------+
|            0.40 |
+-----------------+
pz@abyss:~> mysql -u root -e "select round(rand(),2)";
+-----------------+
| round(rand(),2) |
+-----------------+
|            0.40 |
+-----------------+
pz@abyss:~> mysql -u root -e "select round(rand(),2)";
+-----------------+
| round(rand(),2) |
+-----------------+
|            0.41 |
+-----------------+
pz@abyss:~> mysql -u root -e "select round(rand(),2)";
+-----------------+
| round(rand(),2) |
+-----------------+
|            0.40 |
+-----------------+
[26 Jan 2003 21:00] MySQL Developer
duplicate of #33