mirror of
https://git.suckless.org/9base
synced 2025-08-30 11:53:48 -07:00
20 lines
225 B
C
20 lines
225 B
C
#include <lib9.h>
|
|
|
|
extern long p9lrand(void);
|
|
#define lrand p9lrand
|
|
#define MASK 0x7fffffffL
|
|
|
|
int
|
|
nrand(int n)
|
|
{
|
|
long slop, v;
|
|
|
|
if(n < 0)
|
|
return n;
|
|
slop = MASK % n;
|
|
do
|
|
v = lrand();
|
|
while(v <= slop);
|
|
return v % n;
|
|
}
|