Bug #33 RAND() not seeded upon thread creation
Submitted: 16 Jan 2003 15:18 Modified: 28 Jan 2003 16:46
Reporter: Alexander Keremidarski Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.0 OS:
Assigned to: CPU Architecture:Any

[16 Jan 2003 15:18] Alexander Keremidarski
Description:
When first called RAND() returns 'predictable' results.

Impact is huge as it means simultaneous connections (even close in terms of time) get same value up to 2 digits after floating point.

In real world worst case is with:

SELECT ... ORDRER BY RAND() LIMIT 1;

"Random" row acrually is fixed - from 100 simultaneous web recuests for example 99 will get SAME row. Quite bad for Banners rotating systems.

How to repeat:
# while true; do mysql -B -N -u root -e "select @r:=rand(), round(@r,2)"; done

Observe the result. Depending on system clock it will be something like:

0.40013473797602        0.40
0.40938241166005        0.41
0.40776392762341        0.41
0.40366006400777        0.40
0.40051618907649        0.40
0.40239181127622        0.40
0.40593299959407        0.41
0.40348305218246        0.40
0.40552761629739        0.41

Suggested fix:
Currently RAND() depends on randominit() which is declared in mysys/my_password.c

Writing my_rand.c should be better i.e. moving it out of auth code.
[28 Jan 2003 16:46] MySQL Developer
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem is not the result of a bug.
For a list of more appropriate places to ask for help using MySQL
products, please visit http://www.mysql.com/support/

Thank you for your interest in MySQL.

Not a bug, only not optimal behaviour.
To be fixed in 4.1