Category : Pascal Source Code
Archive   : PASS_ALL.ZIP
Filename : TI134.ASC

 
Output of file : TI134.ASC contained in archive : PASS_ALL.ZIP









PRODUCT : TURBO PASCAL NUMBER : 134
VERSION : 3.0xx
OS : PC-DOS, MS-DOS
DATE : April 2, 1986 PAGE : 1/2
TITLE : RANDOM NUMBER SEED LOCATIONS




Turbo Pascal maintains a four byte random number seed. There is
a Randomize procedure to give that seed a random value which the
function, Random, then uses to generate random values within a
specified range.

Random : r := seed;

The function Random(value) calls the following routine:

function Random(N_Max): real;
var c1, c2, r : real;
begin
c1 := exp(32 * ln(2));
c2 := exp(16 * ln(2));
r := (r * 129 * $361962E9) mod c1;
Random := r div c2 mod N_Max;
end;

The following table gives the random number seed address for most
Turbo Pascal implementations:

Random Number Seed Locations

IBM TURBO.COM 01FC
IBM TURBO-87.COM 01FE
IBM TURBOBCD.COM 0200
Generic TURBO.COM 01DA

The seed may be declared as:

Var RandomSeed: Array [0..3] Of Byte Absolute DSeg:$01FC;

or:

Var RandomSeed: Array [0..1] Of Integer Absolute DSeg:$01FC;

By replacing the value in the address, you can seed the random
number generator in any way you like: read it from a file; read a
number from the user; ask for the user to hit a key, and count
until he does; get the system time; or, assign a constant value.
Using constant values is useful in making statistical simulations
uniform.