summaryrefslogtreecommitdiff
path: root/lib/std/rand.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-09-12 09:01:39 -0700
committerOri Bernstein <ori@eigenstate.org>2015-09-15 23:01:09 -0700
commit610852e18629b8a9a4c4f4ed6e6fc7a336152511 (patch)
treeb69e2c8d29091b688115a499a50521d6d81cad1a /lib/std/rand.myr
parentae9a74441cba3160943ad18bf500781143bff096 (diff)
downloadmc-610852e18629b8a9a4c4f4ed6e6fc7a336152511.tar.gz
Move to use 'for var i = ...' construct.
Diffstat (limited to 'lib/std/rand.myr')
-rw-r--r--lib/std/rand.myr14
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/std/rand.myr b/lib/std/rand.myr
index 2e8c73e..6ca23e6 100644
--- a/lib/std/rand.myr
+++ b/lib/std/rand.myr
@@ -75,13 +75,11 @@ const delrng = {rng
/* initializes a random number generator from the seed `seed`. */
const init = {rng, seed
- var i
-
- for i = 0; i < 624; i++
+ for var i = 0; i < 624; i++
rng.state[i] = seed
seed = 1812433253 * (seed ^ (seed >> 30)) + i + 1
;;
- rng.i = i
+ rng.i = 624
}
/*
@@ -117,10 +115,10 @@ generic rand = {rng, lo, hi -> @a::(integral,numeric)
may be negative, if the type is signed.
*/
generic randN = {rng -> @a::(integral,numeric)
- var i, val
+ var val
val = 0
- for i = 0; i < sizeof(@a)/4; i++
+ for var i = 0; i < sizeof(@a)/4; i++
val <<= 8*sizeof(@a)
val |= rand32(rng) castto(@a::(integral,numeric))
;;
@@ -147,10 +145,10 @@ const rand32 = {rng
}
const randbytes = {rng, buf
- var i, n, r
+ var n, r
n = 0
- for i = 0; i < buf.len/4; i++
+ for var i = 0; i < buf.len/4; i++
r = rand32(rng)
buf[n++] = (r >> 0 & 0xff) castto(byte)
buf[n++] = (r >> 8 & 0xff) castto(byte)