Article View: comp.sys.mac
Article #26348Re: How Doy you get a real random number in LSC?
From: Justin Chris Vallon
Date: Tue, 15 Mar 1988 02:39
Date: Tue, 15 Mar 1988 02:39
20 lines
1345 bytes
1345 bytes
jasst3@cisunx.UUCP (Jeffry A. Sullivan) asks: >> How do you get a real random number in LSC? I have tried using rand() and Random() (from math lib and quickdraw, repectively). They both give the same sequence of numbers each time at startup. I am trying to write a randomizer INIT that works on a mac II, but the randomness is all that's holding me back. (I think...) << The QD function Random() uses the global variable RandSeed, which is always initialized to the same number when you call InitGraf(&thePort). To change the sequence of random numbers, you must initialize the seed. A seed that I use a lot is either the current system time, since it will never be the same for two instances of your initialization. Look for the function which returns the number of seconds elapsed since 1/1/04. Use this number (ANDed w/0xffff) to generate a unique random number seed. -Justin justin.vallon@andrew.cmu.edu
Technical Details
Message-ID:
<0WD9Zey00Xo7sDQ0Cl@andrew.cmu.edu>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!mit-eddie!uw-beaver!cornell!rochester!PT.CS.CMU.EDU!andrew.cmu.edu!jv0l+Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!mit-eddie!uw-beaver!cornell!rochester!PT.CS.CMU.EDU!andrew.cmu.edu!jv0l+ From: jv0l+@andrew.cmu.edu (Justin Chris Vallon) Newsgroups: comp.sys.mac Subject: Re: How Doy you get a real random number in LSC? Message-ID: <0WD9Zey00Xo7sDQ0Cl@andrew.cmu.edu> Date: 15 Mar 88 02:39:38 GMT Organization: Carnegie Mellon University Lines: 19 In-Reply-To: <7671@cisunx.UUCP>