aboutsummaryrefslogtreecommitdiff
path: root/libio/dbz/random.c
diff options
context:
space:
mode:
Diffstat (limited to 'libio/dbz/random.c')
-rw-r--r--libio/dbz/random.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/libio/dbz/random.c b/libio/dbz/random.c
new file mode 100644
index 0000000..1d8de3a
--- /dev/null
+++ b/libio/dbz/random.c
@@ -0,0 +1,31 @@
+/*
+ * random-number generator for testing
+ */
+static unsigned long next = 1;
+
+/*
+ - range - generate a random number within an inclusive range
+ *
+ * Algorithm from ANSI C standard. Limitation: max-min <= 32767.
+ */
+int
+range(min, max)
+int min;
+int max;
+{
+ register int temp;
+
+ next = next * 1103515245 + 12345;
+ temp = (int)((next/65536)%32768);
+ return(temp%(max - min + 1) + min);
+}
+
+/*
+ - seed - seed random number generator
+ */
+void
+seed(n)
+long n;
+{
+ next = (unsigned long)n;
+}