Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!psuvax1!xavier!jackiw From: jackiw@cs.swarthmore.edu (Nick Jackiw) Newsgroups: comp.sys.mac.programmer Subject: Re: Random number Generator wanted. Message-ID: <47XL38V@xavier.swarthmore.edu> Date: 28 Jun 90 16:22:32 GMT References: <152@asacsg.mh.nl> Sender: news@xavier.swarthmore.edu (Usenet News) Reply-To: jackiw@cs.swarthmore.edu (Nick Jackiw) Organization: Visual Geometry Project, Swarthmore College, PA Lines: 37 kr@asacsg.mh.nl (Koos Remigius) writes: .> This function gives me a random integer ( between 0 and range ). .> function Randomize(range:Integer):Integer; .> var .> rawResult:LongInt; { "Raw" random number received from toolbox } .> begin { Randomize } .> rawResult:=(ABS(Random); { Get random number between 0 and 32767 } .> Randomize:=(rawResult * range) div 32768;{ Scale to specified range } .> end; { Randomize } ---------- Much more efficient: Randomize:=abs(random) mod succ(range); ---------- .> .>What I need is a random number generator that gives me a random LongInt back. .> The random number I want must lis between 0 and 2097151. ------ var Randomize:longint; Randomize:=(32768*(abs(random) mod 64)+abs(random)); ------ > Greetings from Holland, > Koos Remigius. Regards from Philadelphia. -- _ _|\____ Nick Jackiw | Visual Geometry Project | Math Department / /_/ O> \ ------------+-------------------------+ Swarthmore College | O> | 215-328-8225| jackiw@cs.swarthmore.edu| Swarthmore PA 19081 \_Guernica_/ ------------+-------------------------+ USA