Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
572 B

  1. #include <windows.h>
  2. #include <port1632.h>
  3. #include "../scrsave.h"
  4. WORD rand(void);
  5. static LONG a = 1234567;
  6. VOID APIENTRY SeedRand(LONG l)
  7. {
  8. a = l;
  9. }
  10. SHORT APIENTRY WRand(w)
  11. UINT w;
  12. {
  13. WORD x = rand() & 0x7fff;
  14. if (w == 0)
  15. return 0;
  16. return x % w;
  17. }
  18. #define m 100000000L
  19. #define m1 10000L
  20. #define b 31415821L
  21. LONG mult(LONG p, LONG q)
  22. {
  23. LONG p1, p0, q1, q0;
  24. p1 = p / m1;
  25. p0 = p % m1;
  26. q1 = q / m1;
  27. q0 = q & m1;
  28. return (((p0 * q1 + p1 * q0) % m1) * m1 + p0 * q0) % m;
  29. }
  30. WORD rand()
  31. {
  32. a = (mult(a, b) + 1) % m;
  33. return (WORD) (a >> 8);
  34. }