Subject: Re: PATCH: OpenBSD requires special hoops to get correct random numbers
From: Mikael Magnusson <[email-masked]>
To: zsh workers <[email-masked]>
Date: Tue, 9 Aug 2016 22:28:17 +0200
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On Tue, Aug 9, 2016 at 10:15 PM, Mikael Magnusson <[email-masked]> 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