Re: Random number question?
From: Peter Webb (webbfamily_at_DIESPAMDIEoptusnet.com.au)
Date: 06/21/04
- Next message: David Bernier: "Re: The Hammer is coming"
- Previous message: Robert Vienneau: "Re: Random number question?"
- In reply to: Paul Allen Panks: "Random number question?"
- Next in thread: Brian Smith: "Re: Random number question?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 21 Jun 2004 16:57:41 +1000
"Paul Allen Panks" <panks@sdf.lonestar.org> wrote in message
news:cb5umk$por$1@chessie.cirr.com...
> How does HLA's random number generator differ from traditional BASIC's
> version? I've long based much of my adventure gaming on random numbers,
> especially during player/monster fighting. Does seeding a number truly
> make it random, or only quasi-random?
>
> Let's say I have a number between 1 and 35. What guarantee do I have that
> the computer won't habitually (or accidentally) pick the same range of
> numbers twice? Or the same individual number twice?
>
> To find out, I wrote a simple QBasic program below:
>
> 1 CLEAR
> 5 CLS : PRINT "Random Number test"
> 10 FOR x = 1 TO 10
> 20 RANDOMIZE TIMER
> 30 i = INT(RND * 35) + 1
> 40 PRINT i
> 45 NEXT x
>
> The program was run three separate times, with the following results:
>
> Test #1
> Random Number test
> 27
> 25
> 17
> 31
> 24
> 18
> 27
> 34
> 23
> 22
>
> Test #2
> Random Number test
> 32
> 29
> 21
> 35
> 29
> 22
> 32
> 4
> 27
> 27
>
> Test #3
> Random Number test
> 21
> 18
> 10
> 24
> 17
> 11
> 21
> 28
> 16
> 16
>
> Ah oh...the last two tests repeated the last two sets of numbers not once
> but TWICE! That's not good!
>
> Now for the same program in HLA:
>
> program random;
> #include ("console.hhf");
> #include ("stdlib.hhf");
> #include ("math.hhf");
> static
> i:int32:=0;
> x:int32:=0;
> begin random;
> console.cls();
> stdout.put("Random number test",nl);
> start:
> add(1,x);
> rand.randomize();
> rand.urange(1,35); // pick a random number, 1 through 35
> mov(eax,i); // move it into i variable
> mov(i,eax); // set i to eax value
> stdout.put(i,nl);
> if(x<10) then
> jmp start;
> endif;
> end random;
>
> The HLA version gives the following 3 results:
>
> Test #1
> Random number test
> 29
> 24
> 11
> 19
> 22
> 8
> 27
> 33
> 27
> 28
>
> Test #2
> Random number test
> 19
> 4
> 32
> 30
> 23
> 34
> 24
> 20
> 20
> 30
>
> Test #3
> Random number test
> 35
> 26
> 29
> 17
> 26
> 18
> 33
> 29
> 19
> 1
>
> Some repeats, but not as bad as before.
>
> Is there a way to truly limit the number of repeats during a set of random
> number generation? I can foresee a lot of random numbers in my own mind,
> but they have to be truly, truly random for the random number generator to
> be doing a good job.
>
> Any ideas as to why both sets of random number generators seem different
> in functionality?
>
> Sincerely,
>
> Paul Panks
> dunric@gmail.com
>
> --
> panks@sdf.lonestar.org
> SDF Public Access UNIX System - http://sdf.lonestar.org
All random numbers generated by a computer program are actually
"pseudo-random". The only way that you can tell is that they will eventually
repeat the same numbers - however, this occurs at a minimum of every 32,768
numbers, and often far higher. Plenty of monsters will die before you start
repeating.
The programs you used generated psuedo-random numbers. If you are generating
numbers between 0 and 35, you will see consecutive repeats (about once every
36 numbers on average). Runs of numbers and other patterns occur far more
often than most people expect. There is nothing anomolous whatsoever about
the repeated numbers which would indicate that the numbers were not random.
If you want to eliminate repeated numbers, you can do this programmatically,
but of course your numbers will no longer be random.
If for whatever reason you want true random numbers, these can be generated
in hardware and lists of such numbers are available on the internet. However
I stress that for simulating dice rolls in a D&D game, I would be very
surprised if the standard rnd() function was inadequate to your needs.
If you want to get really paranoid, notice that in your tests, 45 out of the
60 numbers were in the range 19 .. 36, but only 15 out of 60 were in the
range 1..18. That is a wider variation from a 50:50 split than I would have
expected .... This is almost certainly just me seeing a pattern where none
really exists, the same effect as I describe above.
- Next message: David Bernier: "Re: The Hammer is coming"
- Previous message: Robert Vienneau: "Re: Random number question?"
- In reply to: Paul Allen Panks: "Random number question?"
- Next in thread: Brian Smith: "Re: Random number question?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|