[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#33044: Analysis and proposed patch

From: Tom de Vries
Subject: bug#33044: Analysis and proposed patch
Date: Mon, 15 Oct 2018 20:59:03 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1


I think there are two independent problems here.



scm_seed_to_random_state should be able to handle the case that the seed
argument is a non-narrow string.


The *random-state* variable is documented like this:
Note that the initial value of *random-state* is the same every time
Guile starts up. Therefore, if you don’t pass a state parameter to the
above procedures, and you don’t set *random-state* to
(seed->random-state your-seed), where your-seed is something that isn’t
the same every time, you’ll get the same sequence of “random” numbers on
every run.

However, using scm_from_locale_string to initialize *random-state* makes
it possible that *random-state* differs depending on the locale used
when starting Guile. So, we should use a string that's independent of
the locale settings.


The second problem is fixed by using scm_from_latin1_string instead of
diff --git a/libguile/random.c b/libguile/random.c
index 4051d1f..6f014e1 100644
--- a/libguile/random.c
+++ b/libguile/random.c
@@ -374,7 +374,7 @@ make_rstate (scm_t_rstate *state)
  * Scheme level interface.

-SCM_GLOBAL_VARIABLE_INIT (scm_var_random_state, "*random-state*",
scm_seed_to_random_state (scm_from_locale_string
+SCM_GLOBAL_VARIABLE_INIT (scm_var_random_state, "*random-state*",
scm_seed_to_random_state (scm_from_latin1_string

 SCM_DEFINE (scm_random, "random", 1, 1, 0,
             (SCM n, SCM state),

Tested on 2.0.14 and 2.2.4 tarballs.

- Tom

reply via email to

[Prev in Thread] Current Thread [Next in Thread]