Results 1 to 4 of 4
Thread: Is php's mt_rand() working?
Aug 9, 2000, 07:27 #1
- Join Date
- Nov 1999
- 0 Post(s)
- 0 Thread(s)
I am trying to pick out a random record from a table. I am using the build in RNG mt_rand() (I have also tried rand()) but keep getting the same 'random' number...
I know all about the inherent weaknesses of RNG functions, BUT, in more than 50 runs, I have gotten the same record each time, so clearly something is wrong.
This is the code I am using:
$sql = "SELECT tid FROM tips";
$result = mysql_query($sql);
$max = mysql_num_rows($result);
$seed = time();
$tid = mt_rand(2,$max); # get random number between 2 and max (inc)
$result = mysql_query("SELECT tip FROM tips WHERE tid=$tid");