Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Operating System Utilities /
Chapter 3 - Mathematical and Logical Utilities / Mathematical and Logical Utilities Reference
Routines / Obtaining a Pseudorandom Number


Random

You can use the Random function to obtain a pseudorandom integer.

FUNCTION Random: Integer;
DESCRIPTION
The Random function returns a pseudorandom integer, uniformly distributed in the range -32767 to 32767.

The value Random returns depends solely on the global variable randSeed, which the QuickDraw InitGraf procedure initializes to 1. Each time the Random function executes, it uses a numerical algorithm to change the value of randSeed to prevent it from returning the same value each time it is called.

To prevent your application from generating the same sequence of pseudo-random numbers each time it is executed, initialize the randSeed global variable, when your application starts up, to a volatile long word variable such as the current date and time. If you would like to generate the same sequence of pseudo-random numbers twice, on the other hand, simply set randSeed to the same value before calling Random for each sequence.

ASSEMBLY-LANGUAGE INFORMATION
You can access the global variable randSeed through the system global variable RndSeed.

SEE ALSO
Listing 3-5 on page 3-22, Listing 3-6 on page 3-23, Listing 3-7 on page 3-23,
and Listing 3-8 on page 3-24 for examples of how to use the Random function.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996