From: alaric AT abwillms DOT demon DOT co DOT uk (Alaric B. Williams) Newsgroups: comp.os.msdos.djgpp Subject: Re: Proper use of rand() Date: Sat, 23 Nov 1996 09:05:33 GMT Lines: 47 Message-ID: <848739922.25004.0@abwillms.demon.co.uk> References: <32945672 DOT DB3 AT pobox DOT oleane DOT com> NNTP-Posting-Host: abwillms.demon.co.uk To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp It is possible to obtain numbers with varying degrees of randomness. The next step up from just using rand() is to set the random number 'seed' with srand() from a value that will be different all the time - such as the system clock. Look up the time functions - I can't remember if one uses: srand(clock()); or something else in there. This will produce a different series (nearly) every time, but is still governed by a precise and predictable mathematical law, such that the entire series can be reconstructed from just one known value. If you want less predictable random numbers generate by a more cunning mathematical law, try "isaac". It's an experimental RNG; probably good enough for anything you'd want it for, and hopefully good enough for encryption/security, where the fate of the nation could depend on somebody being unable to predict the sequence! For more about ISAAC, read "http://www.abwillms.demon.co.uk/crypto/". BTW, I didn't write it; Bob Jenkins did. More about that on the page. ISAAC can still be restarted along a given path by being given the same key; so you should key it on something /like/ the system clock, although ISAAC's seed consists of something like 256 integers rather than just one - so perhaps you'd be better timing the change of uclock() between a series of keystrokes from the user, combining the least significant bytes of each of four of these into one integer, and repeating 256 times... If you want true randomness, then invest in a noisy diode or radioactive decay unit to plug into your parallel port. Quantum randomness, and unreproducable! ABW -- "Simply drag your mother in law's cellphone number from the Address Book to the Laser Satellite icon, and the Targeting Wizard will locate her. Then follow the onscreen prompts for gigawattage and dispersion pattern..." (Windows for Early Warning and Defence User's manual P385) Alaric B. Williams Internet : alaric AT abwillms DOT demon DOT co DOT uk Hello :-)