aboutsummaryrefslogtreecommitdiff
path: root/src/lib9/lnrand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib9/lnrand.c')
-rw-r--r--src/lib9/lnrand.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/lib9/lnrand.c b/src/lib9/lnrand.c
new file mode 100644
index 00000000..5b648d08
--- /dev/null
+++ b/src/lib9/lnrand.c
@@ -0,0 +1,18 @@
+#include <u.h>
+#include <libc.h>
+
+#define MASK 0x7fffffffL
+
+long
+lnrand(long n)
+{
+ long slop, v;
+
+ if(n < 0)
+ return n;
+ slop = MASK % n;
+ do
+ v = lrand();
+ while(v <= slop);
+ return v % n;
+}