home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / man / cat3 / random.0 < prev    next >
Text File  |  1993-12-07  |  5KB  |  133 lines

  1.  
  2. RANDOM(3)                  UNIX Programmer's Manual                  RANDOM(3)
  3.  
  4. NNAAMMEE
  5.      rraannddoomm, ssrraannddoomm, iinniittssttaattee, sseettssttaattee - better random number generator;
  6.      routines for changing generators
  7.  
  8. SSYYNNOOPPSSIISS
  9.      ##iinncclluuddee <<ssttddlliibb>>
  10.  
  11.      _l_o_n_g
  12.      rraannddoomm(_v_o_i_d)
  13.  
  14.      _v_o_i_d
  15.      ssrraannddoomm(_u_n_s_i_g_n_e_d _s_e_e_d)
  16.  
  17.      _c_h_a_r _*
  18.      iinniittssttaattee(_u_n_s_i_g_n_e_d _s_e_e_d, _c_h_a_r _*_s_t_a_t_e, _i_n_t _n)
  19.  
  20.      _c_h_a_r _*
  21.      sseettssttaattee(_c_h_a_r _*_s_t_a_t_e)
  22.  
  23. DDEESSCCRRIIPPTTIIOONN
  24.      The rraannddoomm() function uses a non­linear additive feedback random number
  25.      generator employing a default table of size 31 long integers to return
  26.      successive pseudo­random numbers in the range from 0 to (2**31)-1.  The
  27.      period of this random number generator is very large, approximately
  28.      16*((2**31)-1).
  29.  
  30.      The rraannddoomm()/ ssrraannddoomm() have (almost) the same calling sequence and ini­
  31.      tialization properties as rand(3)/ srand(3).   The difference is that
  32.      rand produces a much less random sequence ­­ in fact, the low dozen bits
  33.      generated by rand go through a cyclic pattern.  All the bits generated by
  34.      rraannddoomm() are usable.  For example, `random()&01' will produce a random
  35.      binary value.
  36.  
  37.      Unlike srand,  ssrraannddoomm() does not return the old seed; the reason for
  38.      this is that the amount of state information used is much more than a
  39.      single word.  (Two other routines are provided to deal with restart­
  40.      ing/changing random number generators).  Like rand(3),  however, rraannddoomm()
  41.      will by default produce a sequence of numbers that can be duplicated by
  42.      calling ssrraannddoomm() with `1' as the seed.
  43.  
  44.      The iinniittssttaattee() routine allows a state array, passed in as an argument,
  45.      to be initialized for future use.  The size of the state array (in bytes)
  46.      is used by iinniittssttaattee() to decide how sophisticated a random number gener­
  47.      ator it should use ­­ the more state, the better the random numbers will
  48.      be.  (Current "optimal" values for the amount of state information are 8,
  49.      32, 64, 128, and 256 bytes; other amounts will be rounded down to the
  50.      nearest known amount.  Using less than 8 bytes will cause an error.)  The
  51.      seed for the initialization (which specifies a starting point for the
  52.      random number sequence, and provides for restarting at the same point) is
  53.      also an argument.  The iinniittssttaattee() function returns a pointer to the pre­
  54.      vious state information array.
  55.  
  56.      Once a state has been initialized, the sseettssttaattee() routine provides for
  57.      rapid switching between states.  The sseettssttaattee() function returns a point­
  58.      er to the previous state array; its argument state array is used for fur­
  59.      ther random number generation until the next call to iinniittssttaattee() or
  60.      sseettssttaattee().
  61.  
  62.      Once a state array has been initialized, it may be restarted at a differ­
  63.      ent point either by calling iinniittssttaattee() (with the desired seed, the state
  64.      array, and its size) or by calling both sseettssttaattee() (with the state array)
  65.      and ssrraannddoomm() (with the desired seed).  The advantage of calling both
  66.      sseettssttaattee() and ssrraannddoomm() is that the size of the state array does not
  67.      have to be remembered after it is initialized.
  68.  
  69.      With 256 bytes of state information, the period of the random number gen­
  70.      erator is greater than 2**69 which should be sufficient for most purpos­
  71.      es.
  72.  
  73. AAUUTTHHOORR
  74.      Earl T. Cohen
  75.  
  76. DDIIAAGGNNOOSSTTIICCSS
  77.      If iinniittssttaattee() is called with less than 8 bytes of state information, or
  78.      if sseettssttaattee() detects that the state information has been garbled, error
  79.      messages are printed on the standard error output.
  80.  
  81. SSEEEE AALLSSOO
  82.      rand(3)
  83.  
  84. HHIISSTTOORRYY
  85.      These functions appeared in 4.2BSD.
  86.  
  87. BBUUGGSS
  88.      About 2/3 the speed of rand(3).
  89.  
  90. 4.2 Berkeley Distribution       April 19, 1991                               2
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.