[Gambas-user] UnRandom (?) Rnd - 1.0.14

A Person kztyrvlq at ...966...
Sat Apr 15 01:12:06 CEST 2006


Good Day All . . .

I wrote a game that starts with a randomly chosen player. I have run the 
game in development hundreds (thousands?) of times and I noticed that 
Player 4 seemed to be getting most of the starts.

I created the following code to test the Randomize() and Rnd features 
and in every run up to 100, to 1000, to 10000, to 100000, to 1000000, to 
10000000, and to 100000000 (a long time, almost 7 minutes) the results 
were the same. Player 1 got the least hits. Player 2 got the second 
least hits. Player 3 got the second most hits and Player 4 got the most 
hits.

The printed product of the below code on my machine is:

Most		Player 4	46,210,088	46.2%
2nd Most	Player 3	26,145,322	26.1%
2nd Least	Player 2	15,446,635	15.4%
Least		Player 1	12,197,955	12.1%

A second run gave me:

Most		Player 4	47,863,756	47.8%
2nd Most	Player 3	25,075,674	25.1%
2nd Least	Player 2	14,560,201	14.6%
Least		Player 1	12,500,369	12.5%

It doesn't seem to be more than 1 percentage point out on each run. One 
hundred million is an excellent testing base.

Player 5 is added only to check for any leakage. It was always zero.

I do not have 1.0.15 yet but is this a problem?

As always, what am I doing wrong?

p.s.  I realise that Gambas has other mechanisms for random number 
generation.

. . .
PUBLIC SUB Form_Open()

   DIM iLap AS Integer
   DIM i1 AS Integer
   DIM i2 AS Integer
   DIM i3 AS Integer
   DIM i4 AS Integer
   DIM i5 AS Integer

   DO UNTIL iLap = 100000000 ' one hundred million
     Randomize()
     SELECT CASE Int(Rnd(1, 5))
       CASE 1
         i1 = i1 + 1
       CASE 2
         i2 = i2 + 1
       CASE 3
         i3 = i3 + 1
       CASE 4
         i4 = i4 + 1
       CASE 5
         i5 = i5 + 1
     END SELECT
     iLap = iLap + 1
   LOOP

   PRINT i1, i2, i3, i4, i5

End
. . .

Paul




More information about the User mailing list