Expose an RNG (the one used by our runtime) to Rust via std.

This commit is contained in:
Roy Frostig
2010-07-25 21:45:09 -07:00
parent 7ef9e82f51
commit 5b6e714d05
7 changed files with 114 additions and 25 deletions

25
src/lib/rand.rs Normal file
View File

@@ -0,0 +1,25 @@
/**
* Bindings the runtime's random number generator (ISAAC).
*/
native "rust" mod rustrt {
type rctx;
fn rand_new() -> rctx;
fn rand_next(rctx c) -> u32;
fn rand_free(rctx c);
}
type rng = obj { fn next() -> u32; };
fn mk_rng() -> rng {
obj rt_rng(rustrt.rctx c) {
fn next() -> u32 {
ret rustrt.rand_next(c);
}
drop {
rustrt.rand_free(c);
}
}
ret rt_rng(rustrt.rand_new());
}