1
0

nrand.c 191 B

123456789101112131415161718
  1. #include <u.h>
  2. #include <libc.h>
  3. #define MASK 0x7fffffffL
  4. int
  5. nrand(int n)
  6. {
  7. long slop, v;
  8. if(n < 0)
  9. return n;
  10. slop = MASK % n;
  11. do
  12. v = lrand();
  13. while(v <= slop);
  14. return v % n;
  15. }