home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / MISCTI10.ZIP / TI204.ASC < prev    next >
Encoding:
Text File  |  1988-04-18  |  1.4 KB  |  52 lines

  1. PRODUCT : TURBO PASCAL     NUMBER : 204
  2. VERSION : 2.0xx
  3.      OS : PC-DOS, MS-DOS
  4.    DATE : April 1, 1986
  5.  
  6.   TITLE : RANDOM NUMBER SEED LOCATIONS 
  7.  
  8. Turbo Pascal maintains a four byte random number seed.   There is 
  9. a  Randomize procedure to give that seed a random value which the 
  10. function,  Random,  then uses to generate random values within  a 
  11. specified range.
  12.  
  13. Random :  r := seed;
  14.  
  15. The function Random(value) calls the following routine:
  16.  
  17. function Random(N_Max): real;
  18. var c1, c2, r : real;
  19. begin
  20.   c1 := exp(32 * ln(2));
  21.   c2 := exp(16 * ln(2));
  22.   r  := (r * 129 * $361962E9) mod c1;
  23.   Random := r div c2 mod N_Max;
  24. end;
  25.  
  26. The following table gives the random number seed address for most 
  27. Turbo Pascal implementations:
  28.  
  29. Random Number Seed Locations 
  30.  
  31.   IBM TURBO.COM               0129
  32.   IBM TURBO-87.COM            0116
  33.   Generic TURBO.COM           0129
  34.   Generic TURBO-87.COM        0116
  35.  
  36. The seed may be declared as:
  37.  
  38.   Var RandomSeed: Array [0..3] Of Byte Absolute DSeg:$0129;
  39.  
  40. or:
  41.  
  42.   Var   RandomSeed:   Array   [0..1]  Of  Integer   Absolute         
  43. DSeg:$0129;
  44.  
  45. By  replacing the value in the address,  you can seed the  random 
  46. number generator in any way you like: read it from a file; read a 
  47. number  from the user;  ask for the user to hit a key,  and count 
  48. until he does;  get the system time; or, assign a constant value. 
  49. Using constant values is useful in making statistical simulations 
  50. uniform.
  51.  
  52.