Hi! Applesoft Basic's random number generator is surprisingly good when compared with those implemented in other flavours of Microsoft Basic (specially the GW-BASIC and QBASIC series from the IBM PC!). I don't think the figures you're getting are bad at all, but you have to take into account the way random numbers are generated by a computer.
To generate random numbers, the computer takes an integer "seed" (more on this later), makes some obscure transformations on it, and with the number obtained, it calculates the random number (in the range [0..1] ) and re-initializes the seed. The transformations are built in a way that there's no way to say what will result from a given seed. Other factors, such as the system date and time, or an internal counter in the processor, can be taken to make the proccess more random. The matter is that gcc's standards libraries use a 32 or 64-bit seed (can't remember what size it is exactly), but Applesoft (as all 8-bit Basic flavour I know about) use a 16-bit seed. Other difference is the way the seed is initialited: as the Apple II doesn't have a clock on the motherboard, Applesoft can't rely on it being present, and uses a counter that runs while the computer is iddle waiting for a keypress (if you read the keyboard using ROM routines, that is). Because of that (the 16-bit versus 32/64-bit seed), if your program runs for large periods of time without asking for a keypress, it is in clear disadvantage against the Linux version, and can start spitting the same series of "random" numbers periodically. In theory, this should happen before the 65,536th (2^16) iteration of the loop. But, as I said at the beginning, whe should be grateful for the Applesoft's random number generator being as good as it is. It wasn't provided for more than making games funnier, and can't compete with a full featured generator created in the age of data encription :-) . Greetings, Antonio Rodr�guez (Grijan) <ftp://grijan.cjb.net:21000/> Ron Hudson ha escrito: > Is there something I should know about rnd() like it runs out of random > numbers after a short time? > > I am using x = int(rnd(1)*2) to flip a coin.. > > like this: > > flip a coin > heads=0 > tails=0 > count=0 > max=0 > > a: > run = 0 > > b: > save old coin, flip a new coin > count = count + 1 > if new coin is heads then heads = heads + 1 else tails = tails + 1 > if old coin <> new coin goto a > run = run + 1 > if run <= max goto b > print count,run,heads,tails > max = run > if max < 25 goto b > > so far I have flipped 12,081,568 coins and only have had 18 in a row > (max = 18) > > I run the same program on my linux machine and 18 occurs at only > 800,000 and by 28,000,000 > the max=20. topping out at 26,671,835 to reach 25. written in C, using > random function. > > So the apple basic program is running many many more flips to get to > the run of 25... > > ??!!?? -- Apple2list is sponsored by <http://lowendmac.com/> and... / Buy books, CDs, videos, and more from Amazon.com \ / <http://www.amazon.com/exec/obidos/redirect-home/lowendmac> \ Support Low End Mac <http://lowendmac.com/lists/support.html> Apple2list info: <http://lowendmac.com/lists/apple2.html> --> AOL users, remove "mailto:" Send list messages to: <mailto:[email protected]> To unsubscribe, email: <mailto:[EMAIL PROTECTED]> For digest mode, email: <mailto:[EMAIL PROTECTED]> Subscription questions: <mailto:[EMAIL PROTECTED]> Archive: <http://www.mail-archive.com/apple2list%40mail.maclaunch.com/> iPod Accessories for Less at 1-800-iPOD.COM Fast Delivery, Low Price, Good Deal www.1800ipod.com
