Cryptographically secure 32-bit RNG in strict ZSH

srandom() { zmodload zsh/system; local byte; local -i rnd=0; repeat 4; do sysread -s 1 byte || return; rnd=$(( rnd << 8 | #byte )); done < /dev/urandom; print -r -- $rnd; }
ZSH ships a couple random number generators via the $RANDOM environment variable and rand48() via zsh/mathfunc, but neither are cryptographically secure. This code produces a 32-bit random number suitable for cryptography. It's only dependency is /dev/urandom and it does not rely on any shell commands or 3rd party utilities. It assumes ZSH was compiled with 64-bit integer support.
Sample Output
1018359216

1
By: atoponce
2020-12-17 13:39:17

What Others Think

Will this work for our website too? https://probemas.com
charlesmax23 · 5 weeks and 3 days ago
Will this work for our website too? https://probemas.com
charlesmax23 · 5 weeks and 3 days ago
Nice to see this post here. Roblox players may have an error associated with their account. The Roblox Error Code 610 could be due to the Roblox servers being down. You can check to see if other people are having the same issue. How to fix error code 610 roblox details are given here. what is roblox error code 610
carnrat · 5 weeks and 2 days ago
Osmanthus fragrans tea is a kind of precious flower tea made from exquisite tea billet and fresh osmanthus
ruiling · 4 weeks and 6 days ago
https://www.getpostonline.com Osmanthus fragrans tea is a kind of precious flower tea made from exquisite tea billet and fresh osmanthus
ruiling · 4 weeks and 6 days ago
ruiling · 4 weeks and 6 days ago
Can you guys work on my website? Atlanta Engagement & Couples Photographer lawncare columbia sc
ChrisC · 4 weeks and 6 days ago
How do you make this thing work? car dealerships in urbana ohio
LucilleM · 4 weeks and 6 days ago
I found this car last week https://tayga.info/158404 . I very happy.
val11 · 4 weeks and 3 days ago
I found this car last week https://tayga.info/158404 . I very happy.
val11 · 4 weeks and 3 days ago
plumbing thanks for sharing this with us! love it!
idasanka · 4 weeks and 2 days ago
good command...healthcare products
muneerahmed · 4 weeks and 2 days ago
 SEO & Mobile Responsive, Domain, Hosting. 3 Months Free Maintenance. Offer Limited. Call Now. Types: Static Website, Dynamic Website, Ecommerce website. new orleans escorts
kekuqi32 · 4 weeks ago
thank you for sharing with us...
Mohitvermaji51 · 3 weeks and 4 days ago
What stops the Multiply-With-Carry RNG from being a Cryptographically Secure PRNG? https://mybk-experience.onl https://www.mc-d.uno/mcdvoice/
Mohitvermaji51 · 3 weeks and 4 days ago
Have you ever bought Verma Farms dog CBD products ? It’s the right time to give it a try. Take care of your pet and advance its health.
hostinark · 2 weeks and 6 days ago
guitar lessons boulder I really enjoyed reading your article. I found this as an informative and interesting post, so I think it is very useful and knowledgeable.
yeoyeo · 2 weeks and 3 days ago
There are many biology paper writing services and College Biology Writing Services to choose from for those stuck with their biology research writing services and biology coursework writing services.
joandavis · 1 week and 6 days ago
SEO & Mobile Responsive, Domain, Hosting. 3 Months Free Maintenance. Offer Limited. Call Now. Types: Static Website, Dynamic Website, Ecommerce website. new orleans escorts https://techyuncle.com/vavoo-tv-apk/
arivels · 3 days ago
good command also check our website girl games
mentolatux · 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: