Article View: comp.sys.mac
Article #12879Re: Random number Generator wanted.
From: Marc T. Kaufman
Date: Fri, 29 Jun 1990 02:07
Date: Fri, 29 Jun 1990 02:07
84 lines
2790 bytes
2790 bytes
In article <152@asacsg.mh.nl> kr@asacsg.mh.nl (Koos Remigius) writes: >What I need is a random number generator that gives me a random LongInt back. If you have a Mac II, the following might help.: Marc Kaufman (kaufman@Neon.stanford.edu) *** SEG 'Main' ******************************************************************* * ROUTINE Random.a * FUNCTION Provide Minimal-Standard random number generator * CALLING C-compatible calling sequences * * This generator is taken from CACM, October 1988, p.1192 * * It was designed by Stephen K. Park and Keith W. Miller * * For future reference: Possible better multipliers are 48271 and 69621 ******************************************************************* CASE ON MACHINE MC68020 PROC ENTRY MSRandomSeed Start DC.W ' ) Copyright Kaufman Research, 1988 ' MSRandomSeed DC.L 1 ; Place to store seed value ENDPROC ******************************************************************* * ROUTINE MSGetSeed * FUNCTION Return the current seed value * INPUT none * OUTPUT D0 = the seed ******************************************************************* MSGetSeed FUNC EXPORT move.l MSRandomSeed,D0 rts ENDFUNC ******************************************************************* * ROUTINE MSRandom * FUNCTION Return the next random number * INPUT none * OUTPUT D0 = the number ******************************************************************* MSRandom FUNC EXPORT lea MSRandomSeed,A0 move.l (A0),D1 mulu.l #16807,D0:D1 ; long multiply divu.l #$7fffffff,D0:D1 ; modulo 2^31 -1 move.l D0,(A0) rts ENDFUNC ******************************************************************* * ROUTINE MSRanSet * FUNCTION Set the random number seed * INPUT The seed value * OUTPUT The seed value ******************************************************************* MSRanSet FUNC EXPORT move.l 4(A7),D0 ; the value the user wants to use and.l #$7fffffff,D0 beq.s MSGetSeed ; zero is not a valid value cmp.l #$7fffffff,D0 beq.s MSGetSeed ; neither is 2^31-1 lea MSRandomSeed,A0 move.l D0,(A0) rts ENDFUNC END
Technical Details
Message-ID:
<1990Jun29.020739.9146@Neon.Stanford.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!eos!shelby!neon!kaufmanReferences:
<152@asacsg.mh.nl>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!eos!shelby!neon!kaufman From: kaufman@Neon.Stanford.EDU (Marc T. Kaufman) Newsgroups: comp.sys.mac,comp.sys.mac.programmer,comp.sys.mac.misc,comp.sys.mac.system Subject: Re: Random number Generator wanted. Keywords: Random number Message-ID: <1990Jun29.020739.9146@Neon.Stanford.EDU> Date: 29 Jun 90 02:07:39 GMT References: <152@asacsg.mh.nl> Organization: Computer Science Department, Stanford University Lines: 84