home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / mrandom / README < prev   
Encoding:
Text File  |  1991-12-12  |  1.6 KB  |  33 lines

  1. I wrote this package to overcome some troubles I had with the random() 
  2. package.  I had been saving random()'s state table to a disk file, then
  3. restarting the random sequence in the next program run.  I discovered some
  4. seriously non-random behavior in the numbers resulting from this practice.
  5. Further investigation (including examination of the object code for
  6. random() -- painful!) showed me that it is necessary to count the number of
  7. calls to random() in order to safely restart it.  Hence the enclosed code.
  8.  
  9. I believe random(), with my modifications, is superior in many respects
  10. to its competition within 4.3bsd Unix, namely rand() and rand48().
  11. Those generators are based on a multiplicative congruential scheme,
  12. which makes them difficult to use in applications where one is generating
  13. points uniformly distributed on the unit square.  Certainly rand() has
  14. the problem that a high-resolution 2-d plot of the x-y points generated by
  15.     for (i=0; i<n; i++) {
  16.       x[i] = rand()/MAXLONG;
  17.       y[i] = rand()/MAXLONG;
  18.     } 
  19. will show stripes.  Using rand()%m is suicidal, since its low-order bits
  20. are known to be cyclic.  Perhaps I'm selling rand48() short, since I haven't
  21. examined it in detail: quite possibly its constants were chosen to minimize
  22. the separation between the stripes in a 2-d plot.
  23.  
  24. To help you get started, I have also enclosed a test-driver called mrtest.
  25.  
  26. Please let me know if you find any defects in the sequence generated
  27. by the default seed built into mrtest.  I picked that seed for
  28. sentimental reasons: it was the last number generated by my old,
  29. and now discredited, random() sequence.
  30.  
  31.                         Clark Thomborson
  32.                         cthombor@gw.d.umn.edu
  33.