mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-15 16:20:17 +02:00
Revert "random-state-from-platform: simplify pid conditional, and clarify docs."
This reverts commit 08904661a2
.
This commit is contained in:
parent
08904661a2
commit
444b26f739
2 changed files with 12 additions and 11 deletions
|
@ -1872,9 +1872,9 @@ read back with the Scheme reader.
|
||||||
Construct a new random state seeded from a platform-specific source of
|
Construct a new random state seeded from a platform-specific source of
|
||||||
entropy, appropriate for use in non-security-critical applications.
|
entropy, appropriate for use in non-security-critical applications.
|
||||||
Currently @file{/dev/urandom} is tried first, or else the seed is based
|
Currently @file{/dev/urandom} is tried first, or else the seed is based
|
||||||
on the time, date, process ID (if scm_getpid is present), an address
|
on the time, date, process ID, an address from a freshly allocated heap
|
||||||
from a freshly allocated heap cell, an address from the local stack
|
cell, an address from the local stack frame, and a high-resolution timer
|
||||||
frame, and a high-resolution timer if available.
|
if available.
|
||||||
@end deffn
|
@end deffn
|
||||||
|
|
||||||
@defvar *random-state*
|
@defvar *random-state*
|
||||||
|
|
|
@ -653,11 +653,11 @@ SCM_DEFINE (scm_random_exp, "random:exp", 0, 1, 0,
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
|
|
||||||
/* Return a new random-state seeded from the time, date, process ID (if
|
/* Return a new random-state seeded from the time, date, process ID, an
|
||||||
scm_getpid is present), an address from a freshly allocated heap
|
address from a freshly allocated heap cell, an address from the local
|
||||||
cell, an address from the local stack frame, and a high-resolution
|
stack frame, and a high-resolution timer if available. This is only
|
||||||
timer if available. This is only to be used as a last resort, when
|
to be used as a last resort, when no better source of entropy is
|
||||||
no better source of entropy is available. */
|
available. */
|
||||||
static SCM
|
static SCM
|
||||||
random_state_of_last_resort (void)
|
random_state_of_last_resort (void)
|
||||||
{
|
{
|
||||||
|
@ -665,9 +665,6 @@ random_state_of_last_resort (void)
|
||||||
SCM time_of_day = scm_gettimeofday ();
|
SCM time_of_day = scm_gettimeofday ();
|
||||||
SCM sources = scm_list_n
|
SCM sources = scm_list_n
|
||||||
(scm_from_unsigned_integer (SCM_UNPACK (time_of_day)), /* heap addr */
|
(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_get_internal_real_time (), /* high-resolution process timer */
|
||||||
scm_from_unsigned_integer ((scm_t_bits) &time_of_day), /* stack addr */
|
scm_from_unsigned_integer ((scm_t_bits) &time_of_day), /* stack addr */
|
||||||
scm_car (time_of_day), /* seconds since midnight 1970-01-01 UTC */
|
scm_car (time_of_day), /* seconds since midnight 1970-01-01 UTC */
|
||||||
|
@ -675,6 +672,10 @@ random_state_of_last_resort (void)
|
||||||
SCM_UNDEFINED);
|
SCM_UNDEFINED);
|
||||||
SCM seed = SCM_INUM0;
|
SCM seed = SCM_INUM0;
|
||||||
|
|
||||||
|
#ifdef HAVE_POSIX
|
||||||
|
sources = scm_cons (scm_getpid (), sources); /* process ID */
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Concatenate the sources bitwise to form the seed */
|
/* Concatenate the sources bitwise to form the seed */
|
||||||
while (scm_is_pair (sources))
|
while (scm_is_pair (sources))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue