Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!uunet!zephyr.ens.tek.com!tektronix!nosun!qiclab!m2xenix!puddle!f42.n161.z1.fidonet.org!Frank.Warren From: Frank.Warren@f42.n161.z1.fidonet.org (Frank Warren) Newsgroups: comp.lang.modula2 Subject: Re: RND FUNCTION NEEDED Message-ID: <2168.275C00D8@puddle.fidonet.org> Date: 3 Dec 90 02:55:14 GMT Sender: ufgate@puddle.fidonet.org (newsout1.26) Organization: FidoNet node 1:161/42 - Records Department, Pleasanton CA Lines: 25 The best way to do it, unless you're into native code, is to use several prime numbers as multipliers, a prime as the modulus, and give up a few numbers. I've been playing with a 16-bitter that uses numbers like 7411 etc for multipliers, and 65521 for the modulus. With 5 of these multipliers, I get periods that are well beyond 10 million; I haven't had the patience to wait until the sequence repeats. It's slower than lesser generators, but I think you'll agree that such a period is remarkable for 16 bit arithmetic. The key is that you use LONGCARDs to hold the result and avoid getting cut off at the knees. This will work for you, but is not canned code I can pass alon since it is proprietary. The principle works with all numbers, though. What I suggest you also do is have counts to see to it you don't fall into a "hole". Some choices of multipliers for the linear congruential method deteriorate into subcycle generators (one of the reasons for using primes to begin with; they tend not to suffer from this). The reason for the longer period is that you get intermixed combinations from each of the LCG's you use. This method fares poorly on the spectral test, but it does produce good pseudo-random sequences. -- uucp: uunet!m2xenix!puddle!161!42!Frank.Warren Internet: Frank.Warren@f42.n161.z1.fidonet.org Brought to you by Super Global Mega Corp .com