1 message in com.mysql.lists.bugsRe: RAND(n) generates same sequence o...
FromSent OnAttachments
Benjamin Pflugmann17 Nov 2001 06:15 
Subject:Re: RAND(n) generates same sequence of numbers
From:Benjamin Pflugmann (benj@pflugmann.de)
Date:11/17/2001 06:15:38 AM
List:com.mysql.lists.bugs

Hi.

On Mon, Nov 05, 2001 at 10:57:30PM -0800, war@warrenweiss.com wrote:

The MySQL RAND(n) function generates same sequence of numbers, no matter what number is used for the seed!

I it would have been helpful, if you provided an example to prove your claim.

mysql> select version(); +-------------+ | version() | +-------------+ | 3.23.38-log | +-------------+ 1 row in set (0.00 sec)

mysql> select rand(); +------------------+ | rand() | +------------------+ | 0.94154374761651 | +------------------+ 1 row in set (0.07 sec)

mysql> select rand(); +-----------------+ | rand() | +-----------------+ | 0.1044417089824 | +-----------------+ 1 row in set (0.00 sec)

mysql> select rand(10); +------------------+ | rand(10) | +------------------+ | 0.18109053110805 | +------------------+ 1 row in set (0.00 sec)

mysql> select rand(); +-----------------+ | rand() | +-----------------+ | 0.7502322306393 | +-----------------+ 1 row in set (0.00 sec)

mysql> select rand(20); +------------------+ | rand(20) | +------------------+ | 0.18109056370434 | +------------------+ 1 row in set (0.00 sec)

mysql> select rand(); +------------------+ | rand() | +------------------+ | 0.75023236568107 | +------------------+ 1 row in set (0.01 sec)

mysql> select rand(30); +------------------+ | rand(30) | +------------------+ | 0.18109059630063 | +------------------+ 1 row in set (0.00 sec)

mysql> select rand(40); +------------------+ | rand(40) | +------------------+ | 0.18109062889692 | +------------------+

I cannot reproduce what you said. The numbers are different for different seeds.

But for my taste the numbers are to similar. Even worse, the following sequences stay similar. E.g. the sequences for rand(10) and rand(11) only differ by 0.18 after 10 iterations. That's not good, IMHO.

I had a look at the code and the problem seems, that the calculation is most times only mildly influenced by small offsets (and the seed is effectively only added for small-medium seeds).

Forwarded to bu@lists.mysql.com, because it is reproducable and could be considered a bug, depending on requirements.

Bye,

Benjamin.