|
PowerBASIC Forums
![]() PowerBASIC for DOS
![]() Random number question?
|
| next newest topic | next oldest topic |
| Author | Topic: Random number question? |
|
Paul Panks Member |
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 The program was run three separate times, with the following results: Test #1 Test #2 Test #3 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; The HLA version gives the following 3 results: Test #1 Test #2 Test #3 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 IP: Logged |
|
Michael Mattias Member |
Series of random numbers <> series of unique numbers. Random means random, meaning "might repeat" IP: Logged |
|
Ian Cairns Member |
The numbers provided by a random number generator are not truly random, but that doesn't necessarily affect a short-term number series. If you are only doing a heads/tails choice, it shouldn't matter. If you are doing a series of choices, like shuffling a deck, then create an array, randomize the array and run through the array with a pointer to pick up the next number in the series. If you want to avoid having the same number twice in a row, then pre-scan the array and delete or replace duplicates. It seems to me (not thoroughly investigated) that the randomness of a numerical sequence deteriorates over time, so I like to re-seed the random number generator after about 50 iterations. I would suggest to do this by adding a number to the original seed number rather than by using "RANDOMIZE" or "RANDOMIZE TIMER" since due to the speed of the compiled program, we might not have advanced to the next seed number and would just repeat the previous series. regards, ------------------ IP: Logged |
|
Bob Zale Administrator |
In PowerBASIC, "randomness" does not deteriorate until about 2^32 iterations. Much larger than 50. {smile} In fact, excessive use of RANDOMIZE (or any other changes) will cause deterioration. Regards, Bob Zale ------------------ IP: Logged |
|
Fred Katzel Member |
Hi I developed the following random number generator back in the '70s to use in developing Fred Katzel. ------------------ IP: Logged |
|
David J Venable Member |
any rng that doesn't get input from some external source will, of course, be pseudo-random (not really random). most PRNG's in compilers are linear congruential generators (LCG) which take the form of:
as far as randomness goes, LCG's are not very random at all. bob referred to the randomness "deteorating" but most LCD's will just begin to repeat after Y digits (depends on the values of a, b and M) (Y is usually not as large as 2^32, so I'm kind of curious as to what type of rng pb uses). additionally, there are combined lcg's which use multiple LCG's in conjunction which will increase the period. but it's still cryptographically weak. for those of you concerned with security LCG's are *not* the way
the nice thing about the Blum Blum Shub generator is that it is unpredictable in both directions so it's perfect for security applications. ------------------ IP: Logged |
All times are EasternTime (US) | next newest topic | next oldest topic |
![]() |
|
Copyright © 1999-2007 PowerBASIC, Inc. All Rights Reserved.