Bug #163 rand(x) is repeatable for the first call for any X

Submitted: 19 Mar 2003 5:07 Modified: 19 Mar 2003 12:11
Reporter: Peter Zaitsev (Basic Quality Contributor) Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:3.23 OS:Any (all)
Assigned to: CPU Architecture:Any

[19 Mar 2003 5:07] Peter Zaitsev
Description:
Rand() is not seeded properly with initialization parameter, resulting in
almost the same number for close seed values.

The behavior is different in MySQL 4.0 so we likely just should backport fix.

How to repeat:
mysql> select round(rand(20),5),round(rand(21),5),round(rand(22),5);
+-------------------+-------------------+-------------------+
| round(rand(20),5) | round(rand(21),5) | round(rand(22),5) |
+-------------------+-------------------+-------------------+
|           0.18109 |           0.18109 |           0.18109 |
+-------------------+-------------------+-------------------+
1 row in set (0.00 sec)

mysql> select rand(20),rand(21),rand(22);
+------------------+------------------+-----------------+
| rand(20)         | rand(21)         | rand(22)        |
+------------------+------------------+-----------------+
| 0.18109056370434 | 0.18109056742963 | 0.1810905702236 |
+------------------+------------------+-----------------+
1 row in set (0.01 sec)
[19 Mar 2003 12:11] Michael Widenius
This should not be backported as it may crash old applications.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.049 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.