Pb with the RAND() function simulating the throw of a 6 sided dices

Pb with the RAND() function simulating the throw of a 6 sided dices

am 16.01.2003 09:54:05 von ZeBoss

Hello to all of you,

I have met a possible bug with the RAND() function in MySQL.

How-To-Repeat:

I use MySQL 3.23.53 and PHP 4.0.6 to make the inserts everything is stored
on a Linux server.

Here is my Table constructor :

CREATE TABLE bb_jets_comp (
Id int(10) unsigned NOT NULL auto_increment,
IdHistoire int(10) unsigned NOT NULL default '0',
Jet1 tinyint(3) unsigned NOT NULL default '0',
Jet2 tinyint(3) unsigned NOT NULL default '0',
Age1 tinyint(3) unsigned NOT NULL default '0',
Age2 tinyint(3) unsigned NOT NULL default '0',
Vieux1 tinyint(3) unsigned NOT NULL default '0',
Vieux2 tinyint(3) unsigned NOT NULL default '0',
IdJoueur int(10) unsigned NOT NULL default '0',
IdComp1 smallint(5) unsigned NOT NULL default '0',
IdComp2 smallint(5) unsigned NOT NULL default '0',
Date datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (Id),
KEY IdJoueur (IdJoueur),
KEY IdHistoire (IdHistoire)
) TYPE=MyISAM COMMENT='Table stockant les jets de compétences';

Here is my INSERT query :

INSERT INTO bb_jets_comp (IdHistoire, Jet1, Jet2, Age1, Age2, Vieux1,Vieux2,
IdJoueur, Date)
VALUES (0, 1+ROUND(RAND()*5), 1+ROUND(RAND()*5), 1+ROUND(RAND()*5),
1+ROUND(RAND()*5), 1+ROUND(RAND()*5), 1+ROUND(RAND()*5), 0, NOW())

I use the RAND function to simulate six throws of a 6 sided dice.

I have written this like that : 1+ROUND(RAND()*5)

This piece of script as worked perfectly well for about 6800 INSERTS. But
from the 2003-01-14 21:51:40 till now the last 130 inserts always began by
a 6 and a 4.

So to reproduce the problem you will probably have to do a loop to insert
approximately 7000 records in the table.

In order for you to understand well, here is a sample of what I get in the
first Inserts I have made :

INSERT INTO bb_jets_comp VALUES (36, 1368, 4, 6, 2, 6, 2, 4, 931, 6,
0,'2002-10-06 03:43:35');
INSERT INTO bb_jets_comp VALUES (37, 1367, 4, 5, 4, 5, 5, 3, 928, 71,
0,'2002-10-06 03:45:57');
INSERT INTO bb_jets_comp VALUES (38, 1334, 5, 2, 3, 2, 2, 2, 259, 6,
0,'2002-10-06 10:19:44');
INSERT INTO bb_jets_comp VALUES (39, 1335, 2, 5, 4, 6, 3, 3, 258, 62,
0,'2002-10-06 10:20:57');
INSERT INTO bb_jets_comp VALUES (40, 1362, 3, 2, 2, 2, 4, 3, 688, 34,
0,'2002-10-06 14:46:23');
INSERT INTO bb_jets_comp VALUES (41, 1361, 2, 2, 1, 4, 2, 2, 684, 6,
0,'2002-10-06 14:48:03');
INSERT INTO bb_jets_comp VALUES (42, 1326, 3, 4, 3, 4, 3, 2, 565, 24,
0,'2002-10-06 19:30:22');
INSERT INTO bb_jets_comp VALUES (43, 1279, 3, 5, 2, 4, 5, 4, 723, 24,
0,'2002-10-06 21:44:29');
INSERT INTO bb_jets_comp VALUES (44, 1415, 4, 2, 5, 5, 4, 5, 85, 14,
0,'2002-10-06 23:17:00');
INSERT INTO bb_jets_comp VALUES (45, 1419, 1, 5, 2, 2, 4, 5, 257, 14,
0,'2002-10-06 23:56:57');
INSERT INTO bb_jets_comp VALUES (46, 1360, 4, 3, 4, 2, 3, 2, 279, 23,
0,'2002-10-07 05:58:49');
INSERT INTO bb_jets_comp VALUES (47, 1435, 3, 3, 3, 3, 1, 4, 553, 17,
0,'2002-10-07 10:49:46');
INSERT INTO bb_jets_comp VALUES (48, 1437, 5, 3, 4, 3, 3, 4, 560, 6,
0,'2002-10-07 10:50:29');
INSERT INTO bb_jets_comp VALUES (49, 1436, 3, 4, 2, 3, 6, 4, 554, 6,
0,'2002-10-07 10:51:17');
INSERT INTO bb_jets_comp VALUES (50, 1434, 6, 4, 3, 1, 1, 2, 1036, 6,
0,'2002-10-07 13:27:47');
INSERT INTO bb_jets_comp VALUES (51, 1526, 2, 5, 5, 4, 5, 3, 362, 6,
0,'2002-10-07 15:15:07');
INSERT INTO bb_jets_comp VALUES (52, 1527, 2, 5, 1, 6, 5, 3, 369, 72,
0,'2002-10-07 15:15:34');
INSERT INTO bb_jets_comp VALUES (53, 1417, 3, 2, 4, 4, 3, 4, 781, 14,
0,'2002-10-07 15:27:38');
INSERT INTO bb_jets_comp VALUES (54, 1534, 6, 4, 6, 1, 3, 6, 311, 80,
0,'2002-10-07 15:34:03');
INSERT INTO bb_jets_comp VALUES (55, 1533, 3, 2, 3, 4, 4, 5, 886, 14,
0,'2002-10-07 15:43:48');
INSERT INTO bb_jets_comp VALUES (56, 1477, 4, 3, 1, 5, 2, 3, 287, 6,
0,'2002-10-07 19:39:00');
INSERT INTO bb_jets_comp VALUES (57, 1499, 5, 4, 3, 4, 2, 2, 244, 57,
0,'2002-10-07 19:55:59');
INSERT INTO bb_jets_comp VALUES (58, 1498, 5, 5, 3, 5, 2, 6, 247, 26,
0,'2002-10-07 19:56:05');
INSERT INTO bb_jets_comp VALUES (59, 1580, 6, 5, 5, 4, 3, 3, 389, 14,
0,'2002-10-08 10:11:43');
INSERT INTO bb_jets_comp VALUES (60, 1581, 5, 2, 1, 3, 5, 2, 392, 38,
0,'2002-10-08 10:12:37');
INSERT INTO bb_jets_comp VALUES (61, 1582, 4, 3, 5, 4, 6, 5, 400, 32,
0,'2002-10-08 10:14:22');

Notice that the 6 throws seem to be really random.
And here is what I get now :

INSERT INTO bb_jets_comp VALUES (6862, 38288, 6, 4, 4, 1, 2, 3, 19624, 80,0,
'2003-01-15 11:35:08');
INSERT INTO bb_jets_comp VALUES (6863, 38289, 6, 4, 4, 1, 3, 2, 19625, 23,0,
'2003-01-15 11:35:19');
INSERT INTO bb_jets_comp VALUES (6864, 38254, 6, 4, 4, 2, 5, 2, 20751, 80,0,
'2003-01-15 12:00:39');
INSERT INTO bb_jets_comp VALUES (6865, 38302, 6, 4, 4, 2, 4, 2, 17350, 80,0,
'2003-01-15 12:01:43');
INSERT INTO bb_jets_comp VALUES (6866, 38299, 6, 4, 4, 2, 3, 2, 16379, 80,0,
'2003-01-15 12:04:18');
INSERT INTO bb_jets_comp VALUES (6867, 38255, 6, 4, 4, 5, 4, 3, 19932, 0,
0,'2003-01-15 12:05:32');
INSERT INTO bb_jets_comp VALUES (6868, 38305, 6, 4, 5, 3, 1, 1, 9657, 80,
0,'2003-01-15 12:07:00');
INSERT INTO bb_jets_comp VALUES (6869, 38300, 6, 4, 4, 6, 2, 5, 16384, 6,
0,'2003-01-15 12:09:05');
INSERT INTO bb_jets_comp VALUES (6870, 38301, 6, 4, 4, 2, 5, 6, 16840, 80,0,
'2003-01-15 12:10:05');
INSERT INTO bb_jets_comp VALUES (6871, 38173, 6, 4, 4, 6, 1, 4, 15789, 2,
0,'2003-01-15 12:12:02');
INSERT INTO bb_jets_comp VALUES (6872, 38174, 6, 4, 4, 6, 1, 3, 15790, 2,
0,'2003-01-15 12:12:37');
INSERT INTO bb_jets_comp VALUES (6873, 38175, 6, 4, 4, 5, 2, 3, 15793, 80,0,
'2003-01-15 12:12:47');
INSERT INTO bb_jets_comp VALUES (6874, 38172, 6, 4, 4, 1, 2, 1, 20853, 71,0,
'2003-01-15 12:16:27');
INSERT INTO bb_jets_comp VALUES (6875, 38063, 6, 4, 4, 3, 6, 4, 9838, 57,
0,'2003-01-15 12:29:39');
INSERT INTO bb_jets_comp VALUES (6876, 38065, 6, 4, 4, 3, 4, 2, 12081, 80,0,
'2003-01-15 12:30:04');
INSERT INTO bb_jets_comp VALUES (6877, 38064, 6, 4, 4, 5, 1, 1, 9839, 6,
0,'2003-01-15 12:30:30');
INSERT INTO bb_jets_comp VALUES (6878, 38062, 6, 4, 4, 2, 3, 3, 9834, 80,
0,'2003-01-15 12:30:54');
INSERT INTO bb_jets_comp VALUES (6879, 38061, 6, 4, 4, 5, 4, 2, 9826, 80,
0,'2003-01-15 12:32:30');
INSERT INTO bb_jets_comp VALUES (6880, 38144, 6, 4, 4, 4, 5, 4, 13159, 0,
0,'2003-01-15 12:32:56');
INSERT INTO bb_jets_comp VALUES (6881, 38167, 6, 4, 4, 3, 6, 3, 17720, 0,
0,'2003-01-15 12:46:39');
INSERT INTO bb_jets_comp VALUES (6882, 38169, 6, 4, 4, 5, 6, 5, 17726, 0,
0,'2003-01-15 12:46:58');
INSERT INTO bb_jets_comp VALUES (6883, 38170, 6, 4, 4, 4, 5, 4, 17728, 0,
0,'2003-01-15 12:47:08');

Notice that the first 2 throws are always 6 and 4, I know it can happen but,
more than 130 times in a row is a bit surprising.

If you need my complete datas I can send you a dump of this table.

Hope it helps you.

Regards

Emmanuel Personne
zeboss@francebloodbowl.com
http://www.francebloodbowl.com/



------------------------------------------------------------ ---------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)

To request this thread, e-mail bugs-thread13488@lists.mysql.com
To unsubscribe, e-mail