isaac.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*Written by Timothy B. Terriberry (tterribe@xiph.org) 1999-2009 public domain.
  2. Based on the public domain implementation by Robert J. Jenkins Jr.*/
  3. #if !defined(_isaac_H)
  4. # define _isaac_H (1)
  5. typedef struct isaac_ctx isaac_ctx;
  6. #define ISAAC_SZ_LOG (8)
  7. #define ISAAC_SZ (1<<ISAAC_SZ_LOG)
  8. #define ISAAC_SEED_SZ_MAX (ISAAC_SZ<<2)
  9. /*ISAAC is the most advanced of a series of Pseudo-Random Number Generators
  10. designed by Robert J. Jenkins Jr. in 1996.
  11. http://www.burtleburtle.net/bob/rand/isaac.html
  12. To quote:
  13. No efficient method is known for deducing their internal states.
  14. ISAAC requires an amortized 18.75 instructions to produce a 32-bit value.
  15. There are no cycles in ISAAC shorter than 2**40 values.
  16. The expected cycle length is 2**8295 values.*/
  17. struct isaac_ctx{
  18. unsigned n;
  19. unsigned r[ISAAC_SZ];
  20. unsigned m[ISAAC_SZ];
  21. unsigned a;
  22. unsigned b;
  23. unsigned c;
  24. };
  25. void isaac_init(isaac_ctx *_ctx,const void *_seed,int _nseed);
  26. unsigned isaac_next_uint32(isaac_ctx *_ctx);
  27. unsigned isaac_next_uint(isaac_ctx *_ctx,unsigned _n);
  28. #endif