9base

revived minimalist port of Plan 9 userland to Unix
git clone git://git.suckless.org/9base
Log | Files | Refs | README | LICENSE

lnrand.c (194B)


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