about summary refs log tree commit diff
path: root/src/rt/rust_rng.cpp
diff options
context:
space:
mode:
authorChris Peterson <cpeterson@mozilla.com>2013-02-14 00:48:40 -0800
committerChris Peterson <cpeterson@mozilla.com>2013-02-14 22:31:08 -0800
commit665e900edeb611a7bfc9b0b911489cb802740945 (patch)
tree9e2361cdcbd298e2f608280cd278df73c6b38637 /src/rt/rust_rng.cpp
parentf4320b6195d2704cf5cb5cb7d23f2b6077a0b34c (diff)
downloadrust-665e900edeb611a7bfc9b0b911489cb802740945.tar.gz
rust-665e900edeb611a7bfc9b0b911489cb802740945.zip
encapsulate isaac RNG in rust_rng struct
Diffstat (limited to 'src/rt/rust_rng.cpp')
-rw-r--r--src/rt/rust_rng.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/rt/rust_rng.cpp b/src/rt/rust_rng.cpp
index 5f4522c4978..3d1e52cb993 100644
--- a/src/rt/rust_rng.cpp
+++ b/src/rt/rust_rng.cpp
@@ -15,7 +15,7 @@
 // Initialization helpers for ISAAC RNG
 
 void
-isaac_seed(rust_kernel* kernel, uint8_t* dest, size_t size) {
+rng_gen_seed(rust_kernel* kernel, uint8_t* dest, size_t size) {
 #ifdef __WIN32__
     HCRYPTPROV hProv;
     kernel->win32_require
@@ -47,7 +47,7 @@ isaac_seed(rust_kernel* kernel, uint8_t* dest, size_t size) {
 #endif
 }
 
-void
+static void
 isaac_init(rust_kernel *kernel, randctx *rctx, rust_vec_box* user_seed) {
     memset(rctx, 0, sizeof(randctx));
 
@@ -64,12 +64,22 @@ isaac_init(rust_kernel *kernel, randctx *rctx, rust_vec_box* user_seed) {
             seed = (seed + 0x7ed55d16) + (seed << 12);
         }
     } else {
-        isaac_seed(kernel, (uint8_t*) &rctx->randrsl, sizeof(rctx->randrsl));
+        rng_gen_seed(kernel, (uint8_t*)&rctx->randrsl, sizeof(rctx->randrsl));
     }
 
     randinit(rctx, 1);
 }
 
+void
+rng_init(rust_kernel* kernel, rust_rng* rng, rust_vec_box* user_seed) {
+    isaac_init(kernel, &rng->rctx, user_seed);
+}
+
+uint32_t
+rng_gen_u32(rust_rng* rng) {
+    return isaac_rand(&rng->rctx);
+}
+
 //
 // Local Variables:
 // mode: C++