Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: rigorously predictable random numbers
On Mon, May 20, 2024 at 7:41 PM Kannan Varadhan <kvaradhan3@xxxxxxxxx> wrote:
>
> Hi folks:
>
> This was an interesting pointer. I am puzzled about some of the
> zsh-isms here and the logic, so
>
> some questions:
>
> > while (( $#bytes < 4 )); do
> > sysread -s$((4-$#bytes)) 'bytes[$#bytes+1]' </dev/urandom || return
> > done
>
> It looks like we want 4 individual byes (the sysread promises anywhere
> from 1 to size of buffer specified, max 8192 (in zshmodules(1)) but may
> return after only reading 1B. So why not only say `-s1` instead of
> the more involved `-s$((4-$#bytes))`?
Reading 1 byte at a time is slower than reading 4 bytes at once.
> > local b1=$bytes[1] b2=$bytes[2] b3=$bytes[3] b4=$bytes[4]
> > return '#b1 << 24 | #b2 << 16 | #b3 << 8 | #b4'
>
> Why copy to a scalar parameters
My goal was to implement the contract described in the comments. This
is how I managed to do it. Your asking "why" appears to imply that you
have another implementation in mind that is more natural to you. If
so, can you post it?
> what does referring to them as '#b1', #b2', ... mean.
These are the numeric values of the bytes held in b1..b4.
% x='A'
% print -r -- $(( #x ))
65
Roman.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author