Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / random.pm
diff --git a/src/tests/random.pm b/src/tests/random.pm
new file mode 100644 (file)
index 0000000..be008ff
--- /dev/null
@@ -0,0 +1,27 @@
+use strict;
+use warnings;
+
+use tests::arc4;
+
+my (@arc4);
+
+sub random_init {
+    if (@arc4 == 0) {
+       my ($seed) = @_;
+       $seed = 0 if !defined $seed;
+       @arc4 = arc4_init (pack ("V", $seed));
+    }
+}
+
+sub random_bytes {
+    random_init ();
+    my ($n) = @_;
+    return arc4_crypt (\@arc4, "\0" x $n);
+}
+
+sub random_ulong {
+    random_init ();
+    return unpack ("V", random_bytes (4));
+}
+
+1;