rand.c 497 B

1234567891011121314151617181920212223242526272829303132
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Simple xorshift PRNG
  4. * see http://www.jstatsoft.org/v08/i14/paper
  5. *
  6. * Copyright (c) 2012 Michael Walle
  7. * Michael Walle <michael@walle.cc>
  8. */
  9. #include <common.h>
  10. #include <rand.h>
  11. static unsigned int y = 1U;
  12. unsigned int rand_r(unsigned int *seedp)
  13. {
  14. *seedp ^= (*seedp << 13);
  15. *seedp ^= (*seedp >> 17);
  16. *seedp ^= (*seedp << 5);
  17. return *seedp;
  18. }
  19. unsigned int rand(void)
  20. {
  21. return rand_r(&y);
  22. }
  23. void srand(unsigned int seed)
  24. {
  25. y = seed;
  26. }