From 07ad0fc2f21fc5f2cbab18e4df7432ef9e8facbb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kochma=C5=84ski?= Date: Mon, 21 Sep 2015 10:22:51 +0200 Subject: [PATCH] init-random: fix #$ for fixnums (allow providing seed) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Kochmański --- src/c/num_rand.d | 28 ++++++++++++++++++++-------- src/c/read.d | 3 +-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/c/num_rand.d b/src/c/num_rand.d index 5d2d84c..ac5eb79 100644 --- a/src/c/num_rand.d +++ b/src/c/num_rand.d @@ -200,16 +200,28 @@ ecl_make_random_state(cl_object rs) cl_object z = ecl_alloc_object(t_random); if (rs == ECL_T) { z->random.value = init_random_state(); - } else { - if (Null(rs)) { - rs = ecl_symbol_value(@'*random-state*'); - } - unlikely_if (!ECL_RANDOM_STATE_P(rs)) { - FEwrong_type_only_arg(@[make-random-state], rs, - @[random-state]); - } + return z; + } + + if (Null(rs)) + rs = ecl_symbol_value(@'*random-state*'); + + switch (ecl_t_of(rs)) { + case t_random: z->random.value = cl_copy_seq(rs->random.value); + break; + case t_fixnum: + z->random.value = init_genrand + (ecl_to_uint32_t(rs)); + break; + /* case t_vector: */ + /* z->random.value = init_by_array(rs, cl_length(rs)); */ + /* break; */ + default: + FEwrong_type_only_arg(@[make-random-state], rs, + @[random-state]); } + return(z); } diff --git a/src/c/read.d b/src/c/read.d index 886f28c..77c70c9 100644 --- a/src/c/read.d +++ b/src/c/read.d @@ -1385,8 +1385,7 @@ sharp_dollar_reader(cl_object in, cl_object c, cl_object d) if (d != ECL_NIL && !read_suppress) extra_argument('$', in, d); c = ecl_read_object(in); - rs = ecl_alloc_object(t_random); - rs->random.value = c; + rs = ecl_make_random_state(c); @(return rs) } -- 2.9.0