On Thu, 2005-08-04 at 15:00 -0400, Scott Hamm wrote:
> I've noticed that rand() do not change on each query request. Is there a way 
> I could get a TRUE randominess into MySQL?

http://dev.mysql.com/doc/mysql/en/mathematical-functions.html

Are you using RAND() or RAND(n)? Using RAND() makes MySQL choose its own
seed (the documentation doesn't specify what seed it will use). If you
choose to seed the random number generator (for example, RAND(3)) and
then start using RAND() it will produce a repeatable sequence.

mysql> SELECT rand(3), rand(), rand();
+------------------+------------------+------------------+
| rand(3)          | rand()           | rand()           |
+------------------+------------------+------------------+
| 0.18109050875631 | 0.75023213843837 | 0.20788919665654 |
+------------------+------------------+------------------+
1 row in set (0.00 sec)

mysql> SELECT rand(), rand(), rand();
+------------------+------------------+------------------+
| rand()           | rand()           | rand()           |
+------------------+------------------+------------------+
| 0.78874959870125 | 0.32008043427028 | 0.23415340598128 |
+------------------+------------------+------------------+
1 row in set (0.01 sec)

mysql> SELECT rand(3), rand(), rand();
+------------------+------------------+------------------+
| rand(3)          | rand()           | rand()           |
+------------------+------------------+------------------+
| 0.18109050875631 | 0.75023213843837 | 0.20788919665654 |
+------------------+------------------+------------------+
1 row in set (0.00 sec)

Notice that the numbers after calling RAND(3) are in the same sequence.

However, in answer to your question, there is no way to get TRUE
randomness in a computer system. Even cryptographically secure random
number generators can be predicted under absolutely identical
circumstances.

-- 
Pat Adams
Applications Programmer
SYSCO Food Services of Dallas

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to