Path: utzoo!mnetor!uunet!husc6!think!ames!ucsd!sdcsvax!ucsdhub!hp-sdd!hplabs!hpda!hpcuhb!hpindda!tribby From: tribby@hpindda.HP.COM (David Tribby) Newsgroups: comp.sys.apple Subject: Re: Random numbers in TML Pascal Message-ID: <6230004@hpindda.HP.COM> Date: 11 Mar 88 17:28:01 GMT References: <439@xroads.UUCP> Organization: HP Information Networks, Cupertino, CA Lines: 32 / cc@xroads.UUCP (Dan McGuirk) / writes... > Does anyone know of a way to generate a random number in TML Pascal? There are two random number tools built into the IIGS: Random is an integer function with no parameters that returns values in the range -32768 to 32767. SetRandSeed(randomSeed) sets the seed (a longInt) for the random number algorithm. (It uses a 32-bit seed to produce a 16-bit number.) The sequence of numbers generated by Random depends upon the seed value. If you use the same seed in different runs of your program, you will get the same sequence of pseudo-random numbers. These tools are located--of all places--in QuickDraw II. Before calling them, you have to load QuickDraw II, allocate memory for its direct page, and start it up. Don't forget to shut down at the end of the program. On a related subject... The examples shipped with TML Pascal do not set the "align on a page" bit when they allocate memory for tools' direct page. This is not always a problem, but sometimes causes very strange results. Be sure you always set that bit in your own programs. When TML Pascal's library starts up SANE for you, it does not set the page alignment bit. One of my programs randomly crashed until I modified it to shut down SANE, allocate a page-aligned block of memory, then restart SANE. This is not a problem unless you are using Real numbers. --Dave Tribby - - - - - ARPA: tribby%hpda@hplabs.HP.COM UUCP: hplabs!hpda!tribby