ref: 89824142bd7d87d1900365f792bfbf5c3fea08f5
parent: 449c1f04cdeaf353c84f0f07e1fc29047197ab5a
author: Ori Bernstein <[email protected]>
date: Wed Aug 15 16:20:13 EDT 2012
Add random number generator tests. The output is suspicious. Needs testing and probably fixes, but at least it compiles.
--- a/bld.sh
+++ b/bld.sh
@@ -48,6 +48,7 @@
alloc.myr\
utf.myr \
fmt.myr \
+ rand.myr \
chartype.myr"
OBJ="$(echo $ASM | sed 's/\.s/.o /g') $(echo $MYR | sed 's/\.myr/.o /g')"
--- a/rand.myr
+++ b/rand.myr
@@ -62,7 +62,7 @@
const mksrng = {seed
var rng
- rng = bytealloc(sizeof(rng)) castto(rng*)
+ rng = alloc()
init(rng, seed)
-> rng
}
--- a/test.myr
+++ b/test.myr
@@ -24,6 +24,7 @@
;;
std.write(1, "Hello, 世界\n")
chartypes()
+ testrng()
std.put("format output %i %i %s %s\n", 123, 321, "asdf", "מִלָּה")
std.put("format with no args\n")
}
@@ -53,5 +54,15 @@
;;
if !std.encode(buf[0:3], -1)
std.write(1, "couldn't encode\n")
+ ;;
+}
+
+const testrng = {
+ var r : std.rng*
+ var i
+
+ r = std.mksrng(42)
+ for i = 0; i < 10; i++
+ std.put("r[%i] = %i\n", i, std.rand32(r))
;;
}