rt: Fix iaac_init using wrong type and not seeding correctly
This was a result of changing the vector representation to contain a box header.
This commit is contained in:
@@ -303,6 +303,17 @@ mod tests {
|
||||
assert ra.gen_str(100u) == rb.gen_str(100u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rng_seeded_custom_seed2() {
|
||||
let seed = [2u8, 32u8, 4u8, 32u8, 51u8];
|
||||
let ra = rand::seeded_rng(seed);
|
||||
// Regression test that isaac is actually using the above vector
|
||||
let r = ra.next();
|
||||
#error("%?", r);
|
||||
assert r == 890007737u32 // on x86_64
|
||||
|| r == 2935188040u32; // on x86
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gen_int_range() {
|
||||
let r = rand::rng();
|
||||
|
||||
@@ -204,7 +204,7 @@ rand_new() {
|
||||
}
|
||||
|
||||
extern "C" CDECL void *
|
||||
rand_new_seeded(rust_vec* seed) {
|
||||
rand_new_seeded(rust_vec_box* seed) {
|
||||
rust_task *task = rust_get_current_task();
|
||||
rust_sched_loop *thread = task->sched_loop;
|
||||
randctx *rctx = (randctx *) task->malloc(sizeof(randctx),
|
||||
|
||||
@@ -128,16 +128,16 @@ inline void isaac_seed(rust_kernel* kernel, uint8_t* dest)
|
||||
}
|
||||
|
||||
inline void
|
||||
isaac_init(rust_kernel *kernel, randctx *rctx, rust_vec* user_seed)
|
||||
isaac_init(rust_kernel *kernel, randctx *rctx, rust_vec_box* user_seed)
|
||||
{
|
||||
memset(rctx, 0, sizeof(randctx));
|
||||
|
||||
char *env_seed = kernel->env->rust_seed;
|
||||
if (user_seed != NULL) {
|
||||
// ignore bytes after the required length
|
||||
size_t seed_len = user_seed->fill < sizeof(rctx->randrsl)
|
||||
? user_seed->fill : sizeof(rctx->randrsl);
|
||||
memcpy(&rctx->randrsl, user_seed->data, seed_len);
|
||||
size_t seed_len = user_seed->body.fill < sizeof(rctx->randrsl)
|
||||
? user_seed->body.fill : sizeof(rctx->randrsl);
|
||||
memcpy(&rctx->randrsl, user_seed->body.data, seed_len);
|
||||
} else if (env_seed != NULL) {
|
||||
ub4 seed = (ub4) atoi(env_seed);
|
||||
for (size_t i = 0; i < RANDSIZ; i ++) {
|
||||
|
||||
Reference in New Issue
Block a user