mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-01-12 12:21:15 -08:00
init-random: fix #$ for fixnums (allow providing seed)
Signed-off-by: Daniel Kochmański <dkochmanski@turtle-solutions.eu>
This commit is contained in:
parent
783f4730a8
commit
07ad0fc2f2
2 changed files with 22 additions and 11 deletions
|
|
@ -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]);
|
||||
}
|
||||
z->random.value = cl_copy_seq(rs->random.value);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue