home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / turbo_c / tcrnd11.arc / RND.DOC < prev    next >
Text File  |  1989-03-10  |  3KB  |  79 lines

  1.  
  2. TCRND by Mark Adler  Pasadena, CA  1987, 1988.
  3.  
  4. RND.ASM is a set of Turbo C subroutines written in assembler to generate
  5. random numbers of high quality at high speed for scientific use.
  6. Include RND.H in any C program that will use the routines.  The
  7. documentation in the source file (RND.ASM) is duplicated here:
  8.  
  9. This module provides two different random number generators, both
  10. augmented by shuffling.  The two methods are linear conguential and
  11. additive generation.  Both run at approximately the same speed.  The
  12. reason for having two is to allow switching between them to check the
  13. sensitivity of the simulation to the random number generation method.
  14. The routines are:
  15.  
  16. void setseed(s)  - Set the seed to the 32 bit value 's' and initialize
  17. long s;            the tables for the additive generator and shuffling.
  18.                    Also sets the method to linear congruential.
  19.  
  20. long seed()      - Return the current linear congruential seed.
  21.  
  22. long ticks()     - Return the current tick count (IBM PC compatibles).
  23.  
  24. long rndmize()   - Same as setseed(ticks()) and returns the seed used.
  25.  
  26. void rndpick(f)  - Select the random number generator method to be used.
  27. int f;             f=0 picks linear congruential, f=1 picks additive.
  28.  
  29. long lrnd()      - Return a 32 bit random number.
  30.  
  31. int rnd(n)       - Return a random number between 0 and n, inclusive.
  32. int n;             (n is a 16 bit integer greater than 0.)
  33.  
  34. double drnd()    - Return a random floating point number in [0..1].
  35.  
  36. void shuffle(a, n) - Shuffle the (16 bit) integer array 'a' with 'n'
  37. int a[], n;          entries.  (Unrelated to the shuffling used in the
  38.                      random number generation.)
  39.  
  40. The expected use is to call either rndmize() or setseed() to set the
  41. seed and initialize the tables, then call rndpick() to select the
  42. generation method, and then any combination of lrnd()'s, rnd()'s,
  43. drnd()'s, and shuffle()'s.  rndpick() should not be used in the middle
  44. of the simulation to try to get a "more random" sequence.  The same
  45. method should be used throughout, but the method can be switched between
  46. runs and the results compared to see if they have any dependence on the
  47. random number generators themselves.
  48.  
  49. The drnd() routine assumes the presence of an 80X87, but does not check
  50. for it.
  51.  
  52. These routines should be easily customizable for use with other
  53. compilers.
  54.  
  55. .OBJ files are provided for all the memory models in the form RND_x.OBJ,
  56. where x is S, C, M, L, or H for small (or tiny), compact, medium, large,
  57. and huge.
  58.  
  59. Also a batch file, RND.BAT, is provided to assemble RND.ASM (which
  60. requires TASM 1.0) for each model and appends it to the appropriate
  61. Turbo C library.  This eliminates the need for project or make files for
  62. small programs that use the routines.
  63.  
  64. See the source file for instructions on assembling and adding the result
  65. to the C libraries.  A set of macros necessary for assembling RND.ASM is
  66. provided.  They allow model independent assembler code to be written and
  67. then assembled for particular models.  Look at RND.ASM for examples on
  68. how to use it.  All the macro names start with an "@".
  69.  
  70. Feel free to send any problems with or comments on TCRND to:
  71.  
  72.         Mark Adler
  73.         P.O. Box 60998
  74.         Pasadena, CA  91106
  75.  
  76.         bitnet: madler@hamlet
  77.         arpa:   madler@hamlet.caltech.edu
  78.  
  79.