News for hackers. Stuff that matters.
Re:Random Numbers in Bash by dennisse on Monday March 27, 2023 @01:13PM (#35329350)
Since no-one asked, I use something like this in zsh:

  rand() {
    local r4
    IFS= read -rk4 -u0 r4 < /dev/urandom || return
    local b1=$r4[1] b2=$r4[2] b3=$r4[3] b4=$r4[4]
    print $(( #b1 << 24 | #b2 << 16 | #b3 << 8 | #b4 ))
  }
It has the added bonus of only using zsh, no external dependencies, so it is quite fast.

There are no comments on this comment yet.