rust/src/lib/rand.rs

36 lines
698 B
Rust
Raw Normal View History

/**
* Bindings the runtime's random number generator (ISAAC).
*/
native "rust" mod rustrt {
type rctx;
fn rand_new() -> rctx;
2011-07-27 07:19:39 -05:00
fn rand_next(c: rctx) -> u32;
fn rand_free(c: rctx);
}
type rng =
obj {
fn next() -> u32 ;
};
fn mk_rng() -> rng {
2011-07-27 07:19:39 -05:00
obj rt_rng(c: rustrt::rctx) {
fn next() -> u32 {
ret rustrt::rand_next(c);
2011-07-27 10:05:34 -05:00
}
drop { rustrt::rand_free(c); }
}
ret rt_rng(rustrt::rand_new());
}
// Local Variables:
// mode: rust;
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End: