rand.c 352 B

1234567891011121314151617181920
  1. #include <stdint.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. static uint32_t x = 123456789;
  5. static uint32_t y = 362436069;
  6. static uint32_t z = 521288629;
  7. static uint32_t w = 88675123;
  8. int rand(void) {
  9. uint32_t t;
  10. t = x ^ (x << 11);
  11. x = y; y = z; z = w;
  12. return abs(w = w ^ (w >> 19) ^ t ^ (t >> 8));
  13. }
  14. void srand(unsigned int seed) {
  15. w ^= seed;
  16. }