home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / mrandom / mrandom.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-12  |  2.3 KB  |  66 lines

  1. /*
  2.  *        mrandom.h
  3.  *
  4.  *    A wrapper for random(), to allow safe restart.
  5.  *
  6.  *    Original Implementation:
  7.  *        Clark Thomborson, September 1991
  8.  *
  9.  *    This material is based upon work supported by the National
  10.  *    Science Foundation under grant number MIP-9023238.  The
  11.  *    Government has certain rights in this material.
  12.  *
  13.  *    Any opinions, findings, and conclusions or recommendations
  14.  *    expressed in this material are those of the author and do
  15.  *    not necessarily reflect the view of the National Science
  16.  *    Foundation.
  17.  *
  18.  *    This code is neither copyrighted nor patented.
  19.  */
  20.  
  21. #define RNGIDSTRLEN 80 /* max length of string written by describe_rng() */
  22.  
  23. char *describe_rng (/* char rngid[RNGIDSTRLEN] */);
  24. /* Write a RNG state identifier into the user-supplied string rngid,
  25.  * which must be of length at least RNGIDSTRLEN.  If the user has not
  26.  * initialized the rng with init_rng(), restart_rng(), or reconstruct_rng(),
  27.  * abort with an error message to stderr.  Otherwise return the value of rngid.
  28.  */
  29.  
  30. int init_rng (/* long seed; char *filename; */);
  31. /* Create a random number statefile initialized with the given seed.
  32.  * Return 1 if file is successfully created, 0 otherwise.
  33.  */
  34.  
  35. int restart_rng (/* char *filename; */);
  36. /* Restart a generator from a statefile.  Print a message on stderr
  37.  * if the restart failed due to a garbled or non-existent statefile, 
  38.  * and return 1.  Otherwise return 0.
  39.  */
  40.  
  41. double frandom ();
  42. /* Generate a uniformly-distributed number a, 0.0 <= a < 1.0, using
  43.  * the 4.3bsd additive congruential generator random().
  44.  */ 
  45.  
  46. long mrandom (/* long m; */);
  47. /* Generate a random integer, uniformly distributed in the range 0..m-1.
  48.  * We use the most-significant bits of the result of a random() call.
  49.  */
  50.  
  51. int save_rng(/* char *filename; */);
  52. /* Save the RNG state to a statefile, after calling random() enough
  53.  * times to reset its internal state variables to their initial values.
  54.  * Check to be sure the RNG can be restarted by calling restart_rng().
  55.  * Return 0 if a problem is detected, printing an error message on stderr.
  56.  * Otherwise return 1.
  57.  */
  58.  
  59. void reconstruct_rng (/* long seed, count1, count2; */);
  60. /* Rebuild a random() state by reseeding the generator, then making
  61.  * (count2*1e9 + count1) calls to random().  Useful for error-checking
  62.  * and error-recovery routines, although it is very slow for large counts.
  63.  */
  64.  
  65. /* end mrandom.h */
  66.