bob8086
Jul 23rd, 2001, 09:15 AM
Can anyone help me out, I need a good random number routine.
I have tried messing aound with the book suggestions but they dont seem random enough, any suggestions will be appreciated
thanks
beachbum
Jul 23rd, 2001, 09:42 AM
How random is random enuff... btw i am posting this msg as a reply to another post and just hoping that it appears on urs by chance! :D
As far as i understand Randomize uses the system timer and so can be relatively random. The Rnd statement returns a single which is a pretty bloody big number. Can u perhaps give more info on what level u are looking for.
Regards
Stuart
bob8086
Jul 23rd, 2001, 11:44 AM
Ive used randomize and rnd for generating groups of numbers, although this does seem to be pretty random I keep getting a simular bias on repeated runs(in excess of 1 million)
Thanks for the response
Guv
Jul 23rd, 2001, 08:25 PM
Random is a subtle concept. In a sense, the term Random Numbers has no meaning. There are random processes which produce data considered to be random. A random process could, on any particular occasion, produce a sequence of numbers which look quite regular.
For critical simulations, I would advise reading up on the subject.
There are computer programs which produce sequences referred to as pseudo random numbers. The programs are known to produce numbers which satisfy various criteria, but which are not universally suitable. Some programs produce uniform distribution statistics, some produce binomial statistics, some produce Poisson statistics, some produce normal curve statistics, others produce Chi-Square statistics.
The VB Rnd function produces random numbers which I believe conform to the statistics of a uniform distribution. Any number between zero and one is equally likely. I do not think that it ever produces exactly one, and I am not sure if it can produce zero. I have heard it said that the Rnd function uses the timer. Actually, the Randomize Statement uses the timer to initialize the Rnd Function. Without the Randomize Statement you get exactly the same sequence of pseudo random numbers every time you run your program, which for some applications is exactly what you want.
Before deciding on a random number generator, you should know the statistics of the process you wish to simulate. Then search the literature for a generator which is expected to produce those statistics.
No pseudo random number generator and no random process produces sequences suitable for all simulation purposes.
There is a web site which supplies sequences of random numbers produced by a radioactive decay process. I think that radioactive decay is a Poisson process.
An internet search should produce a lot of information to help you.
BTW: The VB Rnd Function can be used to simulate the casino craps to about 3-4 decimal digits of precision if you analyze about 500,000 tosses. It does not seem to get more accurate if you simulate tem million or so tosses. This indicates that is not quite the correct generator for simulating casino craps. A true random process produces statistics which match the theoretical statistics more precisely as the number of trials increase. The generator in Quick Basic and other earlier versions of basic indicated that the game favored the player, which is ridiculous. Still that generator was useful for other purposes.
Rnd Function output is usually modified to conform to the problem being simulated. For example: When simulating dice rolls, the Rnd value is multiplied by 6 and truncated to an integer, providing a number in the range zero to five. If need be, one is added to produce 1-6 as the range. When I simulated craps, I used the 0-5 range numbers as array subscripts.