Expose an RNG (the one used by our runtime) to Rust via std.
This commit is contained in:
parent
7ef9e82f51
commit
5b6e714d05
7 changed files with 114 additions and 25 deletions
|
@ -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++
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue