* Fwd: PATCH: OpenBSD requires special hoops to get correct random numbers
[not found] <20160809201539.25399-1-mikachu@gmail.com>
2016-08-09 20:28 ` PATCH: OpenBSD requires special hoops to get correct random numbers Mikael Magnusson
@ 2016-08-10 15:03 ` Mikael Magnusson
2016-08-10 15:13 ` Peter Stephenson
1 sibling, 1 reply; 3+ messages in thread
From: Mikael Magnusson @ 2016-08-10 15:03 UTC (permalink / raw)
To: zsh workers
Apparently gmail decided to eat the original message?
---------- Forwarded message ----------
From: Mikael Magnusson <mikachu@gmail.com>
Date: Tue, Aug 9, 2016 at 10:15 PM
Subject: PATCH: OpenBSD requires special hoops to get correct random numbers
To: zsh-workers@zsh.org
Apparently there was a change in OpenBSD fairly recently[1] that
causes random numbers generated by rand() to ignore the value passed to
srand(). Since zsh guarantees repeatable sequences we have to use their
non-standard interface to continue providing this guarantee.
If someone has an opinion on where to stick the #define or if the two
call-sites should be explicitly #ifdef'd, let me know.
At home,
% zsh -c 'repeat 3 { RANDOM=5; echo $RANDOM }'
23835
23835
23835
On OpenBSD system,
% zsh -c 'repeat 3 { RANDOM=5; echo $RANDOM }'
24254
32257
4161
On OpenBSD system with patch applied,
% Src/zsh -c 'repeat 3 { RANDOM=5; echo $RANDOM }'
14426
14426
14426
[1] http://marc.info/?l=openbsd-cvs&m=141807513728073&w=2
---
Src/zsh_system.h | 4 ++++
configure.ac | 3 ++-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/Src/zsh_system.h b/Src/zsh_system.h
index 17c4c64..a9cbf02 100644
--- a/Src/zsh_system.h
+++ b/Src/zsh_system.h
@@ -882,6 +882,10 @@ extern short ospeed;
# endif
#endif
+#ifdef HAVE_SRAND_DETERMINISTIC
+# define srand srand_deterministic
+#endif
+
#ifdef ZSH_VALGRIND
# include "valgrind/valgrind.h"
# include "valgrind/memcheck.h"
diff --git a/configure.ac b/configure.ac
index 3e9e467..6ee5c5d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1322,7 +1322,8 @@ AC_CHECK_FUNCS(strftime strptime mktime timelocal \
realpath canonicalize_file_name \
symlink getcwd \
cygwin_conv_path \
- nanosleep)
+ nanosleep \
+ srand_deterministic)
AC_FUNC_STRCOLL
AH_TEMPLATE([REALPATH_ACCEPTS_NULL],
--
2.8.2
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: PATCH: OpenBSD requires special hoops to get correct random numbers
2016-08-10 15:03 ` Fwd: " Mikael Magnusson
@ 2016-08-10 15:13 ` Peter Stephenson
0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2016-08-10 15:13 UTC (permalink / raw)
To: zsh workers
On Wed, 10 Aug 2016 17:03:16 +0200
Mikael Magnusson <mikachu@gmail.com> wrote:
> If someone has an opinion on where to stick the #define or if the two
> call-sites should be explicitly #ifdef'd, let me know.
Looks OK to me, given the nature of the problem.
pws
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: PATCH: OpenBSD requires special hoops to get correct random numbers
[not found] <20160809201539.25399-1-mikachu@gmail.com>
@ 2016-08-09 20:28 ` Mikael Magnusson
2016-08-10 15:03 ` Fwd: " Mikael Magnusson
1 sibling, 0 replies; 3+ messages in thread
From: Mikael Magnusson @ 2016-08-09 20:28 UTC (permalink / raw)
To: zsh workers
On Tue, Aug 9, 2016 at 10:15 PM, Mikael Magnusson <mikachu@gmail.com> wrote:
> Apparently there was a change in OpenBSD fairly recently[1] that
> causes random numbers generated by rand() to ignore the value passed to
> srand(). Since zsh guarantees repeatable sequences we have to use their
> non-standard interface to continue providing this guarantee.
>
> If someone has an opinion on where to stick the #define or if the two
> call-sites should be explicitly #ifdef'd, let me know.
>
> At home,
> % zsh -c 'repeat 3 { RANDOM=5; echo $RANDOM }'
> 23835
> 23835
> 23835
> On OpenBSD system,
> % zsh -c 'repeat 3 { RANDOM=5; echo $RANDOM }'
> 24254
> 32257
> 4161
> On OpenBSD system with patch applied,
> % Src/zsh -c 'repeat 3 { RANDOM=5; echo $RANDOM }'
> 14426
> 14426
> 14426
>
> [1] http://marc.info/?l=openbsd-cvs&m=141807513728073&w=2
(The rand48 zsh math function uses erand48() internally, and that is
unaffected by the change.)
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-08-10 15:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20160809201539.25399-1-mikachu@gmail.com>
2016-08-09 20:28 ` PATCH: OpenBSD requires special hoops to get correct random numbers Mikael Magnusson
2016-08-10 15:03 ` Fwd: " Mikael Magnusson
2016-08-10 15:13 ` Peter Stephenson
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).