summaryrefslogtreecommitdiff
path: root/appl/lib/rand.b
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
committerCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
commit37da2899f40661e3e9631e497da8dc59b971cbd0 (patch)
treecbc6d4680e347d906f5fa7fca73214418741df72 /appl/lib/rand.b
parent54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff)
20060303a
Diffstat (limited to 'appl/lib/rand.b')
-rw-r--r--appl/lib/rand.b29
1 files changed, 29 insertions, 0 deletions
diff --git a/appl/lib/rand.b b/appl/lib/rand.b
new file mode 100644
index 00000000..3409cdec
--- /dev/null
+++ b/appl/lib/rand.b
@@ -0,0 +1,29 @@
+implement Rand;
+
+include "rand.m";
+
+rsalt: big;
+
+init(seed: int)
+{
+ rsalt = big seed;
+}
+
+MASK: con (big 1<<63)-(big 1);
+
+rand(modulus: int): int
+{
+ rsalt = rsalt * big 1103515245 + big 12345;
+ if(modulus <= 0)
+ return 0;
+ return int (((rsalt&MASK)>>10) % big modulus);
+}
+
+# 0 < modulus < 2^53
+bigrand(modulus: big): big
+{
+ rsalt = rsalt * big 1103515245 + big 12345;
+ if(modulus <= big 0)
+ return big 0;
+ return ((rsalt&MASK)>>10) % modulus;
+}