diff options
author | Mark H Weaver <mhw@netris.org> | 2013-02-24 19:57:00 -0500 |
---|---|---|
committer | Mark H Weaver <mhw@netris.org> | 2013-02-24 19:57:00 -0500 |
commit | 08904661a2b1c6d461b2f5abfe3226a4023453fb (patch) | |
tree | 2a770e78b75508b3b9f257ba5461063a9c1ed8a1 /libguile/random.c | |
parent | c085589b1c34fa88d28c23cb5e3659fecdb09f33 (diff) | |
download | guile-08904661a2b1c6d461b2f5abfe3226a4023453fb.tar.gz |
random-state-from-platform: simplify pid conditional, and clarify docs.
* libguile/random.c (random_state_of_last_resort): Simplify optional
inclusion of PID in the random state. Clarify in the comments that
the PID is only included where scm_getpid is present.
* doc/ref/api-data.texi (Random): Clarify that
'random-state-from-platform' includes the PID in the random state only
if scm_getpid is present.
Diffstat (limited to 'libguile/random.c')
-rw-r--r-- | libguile/random.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/libguile/random.c b/libguile/random.c index a85ee8147..9cb5e6937 100644 --- a/libguile/random.c +++ b/libguile/random.c @@ -653,11 +653,11 @@ SCM_DEFINE (scm_random_exp, "random:exp", 0, 1, 0, } #undef FUNC_NAME -/* Return a new random-state seeded from the time, date, process ID, an - address from a freshly allocated heap cell, an address from the local - stack frame, and a high-resolution timer if available. This is only - to be used as a last resort, when no better source of entropy is - available. */ +/* Return a new random-state seeded from the time, date, process ID (if + scm_getpid is present), an address from a freshly allocated heap + cell, an address from the local stack frame, and a high-resolution + timer if available. This is only to be used as a last resort, when + no better source of entropy is available. */ static SCM random_state_of_last_resort (void) { @@ -665,6 +665,9 @@ random_state_of_last_resort (void) SCM time_of_day = scm_gettimeofday (); SCM sources = scm_list_n (scm_from_unsigned_integer (SCM_UNPACK (time_of_day)), /* heap addr */ +#ifdef HAVE_POSIX + scm_getpid (), /* process ID */ +#endif scm_get_internal_real_time (), /* high-resolution process timer */ scm_from_unsigned_integer ((scm_t_bits) &time_of_day), /* stack addr */ scm_car (time_of_day), /* seconds since midnight 1970-01-01 UTC */ @@ -672,10 +675,6 @@ random_state_of_last_resort (void) SCM_UNDEFINED); SCM seed = SCM_INUM0; -#ifdef HAVE_POSIX - sources = scm_cons (scm_getpid (), sources); /* process ID */ -#endif - /* Concatenate the sources bitwise to form the seed */ while (scm_is_pair (sources)) { |