Source:NetHack 5.0.0/include/isaac64.h
Jump to navigation
Jump to search
Below is the full text to isaac64.h from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/include/isaac64.h#line12]], for example.
The NetHack General Public License applies to screenshots, source code and other content from NetHack.
This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.
1. /* CC0 (Public domain) - see http://creativecommons.org/publicdomain/zero/1.0/ for details */ 2. #if !defined(_isaac64_H) 3. # define _isaac64_H (1) 4. 5. 6. 7. typedef struct isaac64_ctx isaac64_ctx; 8. 9. 10. 11. #define ISAAC64_SZ_LOG (8) 12. #define ISAAC64_SZ (1<<ISAAC64_SZ_LOG) 13. #define ISAAC64_SEED_SZ_MAX (ISAAC64_SZ<<3) 14. 15. 16. 17. /*ISAAC is the most advanced of a series of pseudo-random number generators 18. designed by Robert J. Jenkins Jr. in 1996. 19. http://www.burtleburtle.net/bob/rand/isaac.html 20. This is the 64-bit version. 21. To quote: 22. ISAAC-64 generates a different sequence than ISAAC, but it uses the same 23. principles. 24. It uses 64-bit arithmetic. 25. It generates a 64-bit result every 19 instructions. 26. All cycles are at least 2**72 values, and the average cycle length is 27. 2**16583.*/ 28. struct isaac64_ctx{ 29. unsigned n; 30. uint64_t r[ISAAC64_SZ]; 31. uint64_t m[ISAAC64_SZ]; 32. uint64_t a; 33. uint64_t b; 34. uint64_t c; 35. }; 36. 37. 38. /** 39. * isaac64_init - Initialize an instance of ISAAC64 random number generator. 40. * @_ctx: The ISAAC64 instance to initialize. 41. * @_seed: The specified seed bytes. 42. * This may be NULL if _nseed is less than or equal to zero. 43. * @_nseed: The number of bytes to use for the seed. 44. * If this is greater than ISAAC64_SEED_SZ_MAX, the extra bytes are 45. * ignored. 46. */ 47. void isaac64_init(isaac64_ctx *_ctx,const unsigned char *_seed,int _nseed); 48. 49. /** 50. * isaac64_reseed - Mix a new batch of entropy into the current state. 51. * To reset ISAAC64 to a known state, call isaac64_init() again instead. 52. * @_ctx: The instance to reseed. 53. * @_seed: The specified seed bytes. 54. * This may be NULL if _nseed is zero. 55. * @_nseed: The number of bytes to use for the seed. 56. * If this is greater than ISAAC64_SEED_SZ_MAX, the extra bytes are 57. * ignored. 58. */ 59. void isaac64_reseed(isaac64_ctx *_ctx,const unsigned char *_seed,int _nseed); 60. /** 61. * isaac64_next_uint64 - Return the next random 64-bit value. 62. * @_ctx: The ISAAC64 instance to generate the value with. 63. */ 64. uint64_t isaac64_next_uint64(isaac64_ctx *_ctx); 65. /** 66. * isaac64_next_uint - Uniform random integer less than the given value. 67. * @_ctx: The ISAAC64 instance to generate the value with. 68. * @_n: The upper bound on the range of numbers returned (not inclusive). 69. * This must be greater than zero and less than 2**64. 70. * To return integers in the full range 0...2**64-1, use 71. * isaac64_next_uint64() instead. 72. * Return: An integer uniformly distributed between 0 and _n-1 (inclusive). 73. */ 74. uint64_t isaac64_next_uint(isaac64_ctx *_ctx,uint64_t _n); 75. /** 76. * isaac64_next_float - Uniform random float in the range [0,1). 77. * @_ctx: The ISAAC64 instance to generate the value with. 78. * Returns a high-quality float uniformly distributed between 0 (inclusive) 79. * and 1 (exclusive). 80. * All of the float's mantissa bits are random, e.g., the least significant 81. * bit may still be non-zero even if the value is less than 0.5, and any 82. * representable float in the range [0,1) has a chance to be returned, though 83. * values very close to zero become increasingly unlikely. 84. * To generate cheaper float values that do not have these properties, use 85. * ldexpf((float)isaac64_next_uint64(_ctx),-64); 86. */ 87. 88. #endif