1
Fork 0

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

View file

@ -127,6 +127,31 @@ vec_len(rust_task *task, type_desc *ty, rust_vec *v)
return v->fill / ty->size;
}
extern "C" CDECL void *
rand_new(rust_task *task)
{
rust_dom *dom = task->dom;
randctx *rctx = (randctx *) task->malloc(sizeof(randctx));
if (!rctx) {
task->fail(1);
return NULL;
}
isaac_init(dom, rctx);
return rctx;
}
extern "C" CDECL size_t
rand_next(rust_task *task, randctx *rctx)
{
return rand(rctx);
}
extern "C" CDECL void
rand_free(rust_task *task, randctx *rctx)
{
task->free(rctx);
}
//
// Local Variables:
// mode: C++