Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!munnari.oz.au!uhccux!caprio From: caprio@uhccux.uhcc.hawaii.edu (Mike Caprio) Newsgroups: comp.lang.c Subject: Re: Random long-number generator Keywords: random maxint Message-ID: <6482@uhccux.uhcc.hawaii.edu> Date: 5 Feb 90 00:06:04 GMT References: <83943@linus.UUCP> <1486@skye.ed.ac.uk> <1540@uniol.UUCP> <1549@mbf.UUCP> Reply-To: caprio@uhccux.UUCP (Mike Caprio) Organization: University of Hawaii Lines: 46 >Nope, no such luck. You see, what I am usually looking for is a good >(best would be _fine_!) RNG which uses integer arithmetic only. Why? >Because I'm a cheapskate who refuses to invest in a floating point >processor for my PC, and also if I ever get around to writing a program >good enough to be worth distributing or (choke) selling, I want it to be >able to run well on as many systems as possible, so FP is out - too many >emulators are TOO SLOW! > >So, how about it? > The following random number generator might be of interest to you. It produces integers in the range 0-2^31, with a period of approx. 2^31. It was published in Modeling and Simulation on Micro- computers (see ref. below), and was tested extensively by the authors. The original code was fortran, but I've run this on Turbo C and the output matched the test output listed in the article. I would check it against that listing if you use a different compiler to be sure. If you can't get ahold of the journal, E-MAIL me and I'll send along at least part of the listing. For the curious, the bit about seed<0 and then adding 2x31 is apparently a quick way to do modulo 2^31 with signed longs. Incidently, this generator is quite fast, quicker than the integer random generator built into Turbo C. long seed; long lrand () { seed = seed * 1220703125L; if (seed < 0) seed += 2147483648L; } From: Dudewicz, E.J., Z. A. Karian and R. J. Marshall III. 1985. Random number generation on microcomputers. pp. 9-14. In R. G. Lavery [ed.], Modeling and simulation on microcomputers:1985. Society for Computer Simulation, La Jolla. _Mike_ caprio@uhccux Opinons? I had one last week...