home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / Classes / Neural-Network / Random.h < prev    next >
Encoding:
Text File  |  1991-05-30  |  2.6 KB  |  91 lines

  1. //
  2. // Random
  3. //
  4. // An Objective-C class for NeXT computers to provide services for random
  5. // number generation and also die rolling.
  6. //
  7. // The Random class implements its own random number generator with a cycle
  8. // length of 8.8 trillion.
  9. // 
  10. // Upon creation of a Random, the seeds are set using the system clock.
  11. // Three calls are made to the system clock function, and for each the 
  12. // microseconds are used as the seed value. Thus, the relationships between
  13. // the seeds are dependant upon system load.
  14. //
  15. // The algorithm used by the Random class is that given in the article:
  16. //   "A Higly Random Random-Number Generator" by T.A. Elkins
  17. //   Computer Language, Volume 6, Number 12 (December 1989), Pages 59-65
  18. //   Published by:
  19. //        Miller Freeman Publications
  20. //        500 Howard Street
  21. //        San Francisco, CA  94105
  22. //        (415) 397-1881
  23. //
  24. // History:
  25. //   pre 1990 Mar 23
  26. //     Used random number generation algorithm from K&R.
  27. //   1990 Mar 23
  28. //     Modified to use algorithm with cycle length of 8.8 trillion.
  29. //   1990 Mar 26
  30. //     * Added archiving.
  31. //     * Added randMax:, randMin:Max:, and percent:.
  32. //   1991 Apr 26
  33. //     * Changed to use +alloc and -init as all NeXTStep 2.0 objects should.
  34. //   1991 May 30
  35. //     * Prepared for distribution and initial release.
  36. //
  37. // Version 1.0, 1991 May 30
  38. //
  39. // Written by Gregor Purdy
  40. // gregor@oit.itd.umich.edu
  41. //
  42. // See the README and COPYING files included for
  43. // information and distribution and usage rights. 
  44. //
  45.  
  46.  
  47. #import <objc/Object.h>
  48. #import <objc/typedstream.h>
  49.  
  50. @interface Random : Object
  51.  
  52. {
  53.     int h1, h2, h3;            // Seeds
  54. }
  55.  
  56. - init;                    // Init with seeds from newSeeds;
  57. - initSeeds:(int)s1            // Init with seeds given.
  58.   :(int)s2
  59.   :(int)s3;
  60.  
  61. - newSeeds;                // Get seeds from system time.
  62. - setSeeds:(int) s1            // Set seeds to those given.
  63.   :(int) s2
  64.   :(int) s3;
  65. - getSeeds:(int *)s1            // Put the seeds into some vars.
  66.   :(int *)s2
  67.   :(int *)s3;
  68.  
  69. - (int)rand;                // Return a random integer.
  70. - (int)randMax:(int)max;        // Return a random integer 0 <= x <= max.
  71. - (int)randMin:(int)min            // Return a random integer min <= x <= max.
  72.   max:(int)max;
  73. - (float) percent;            // Return a random float 0.0 <= x <= 1.0.
  74.  
  75. - (int)rollDie:(int)numSides;        // Return a random integer 1 <= x <= numSides.
  76. - (int)roll:(int)numRolls        // Return the best numWanted of numRolls rolls.
  77.   die:(int)numSides;
  78. - (int)rollBest:(int)numWanted        // Return integer sum of best numWanted rolls.
  79.   of:(int)numRolls
  80.   die:(int)numSides;
  81.  
  82. - read:(NXTypedStream *)stream;        // De-archive from a typed stream.
  83. - write:(NXTypedStream *)stream;    // Archive to a typed stream.
  84.  
  85.  
  86. @end
  87.  
  88.  
  89. //
  90. // End of file.
  91. //