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 doneIt 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.
ok but the loop seems to read 4, then 3, 2, and 1B in each iteration, or did I miss something?
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 parametersMy 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?
i dont have an alternate implementation. I was trying to use
'#bytes[1]' directly and that did not work.
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
Interesting,
Kannan