Skip to content

Instantly share code, notes, and snippets.

@georgepence
Forked from 5c0tt/random_number
Created May 29, 2023 09:22
Show Gist options
  • Select an option

  • Save georgepence/e8ef86463cfa486d624723e074b04755 to your computer and use it in GitHub Desktop.

Select an option

Save georgepence/e8ef86463cfa486d624723e074b04755 to your computer and use it in GitHub Desktop.
Generate random numbers in Mac OS X using /dev/random or /dev/urandom using a shell script
# Make sure to `chmod u+x random_number` in order to make this file go
#!/bin/bash
# Generate random strings on Mac OS X
# the `tr` uses a regex to decide which characters you want to include
# This is very slow as a bash script, random seems faster than urandom
# though I have been told that one just symblinks the other so that would
# then not be possible to be faster.
# Here is some sample output from the below:
# 4o)lATvDFr17gH(*fu2+
# EXF)83gtE*fcIsZYlaDu
# qGA7Pb=Q@w#6F!2mJ8=j
# V6mPClwZ1qZ(X8hxHI@t
# +N1wwS8h#0%jbB1e@z*x
# #vvJMscG*oXs#ex7ivnc
# p(xFYVK)91kJjfXr2!sB
# IW5kB8Q4uvFQm_J%4bbu
# m6^9y=RWroBNfpNzyBXI
# 47=&3Jc5zzAg)X8(OF%s
# )C_I%!6zJ!*appXlz=VE
# Lv@^3rRYQECP)RkxlUs
i="0"
while [[ $i -lt 40 ]];
do
LC_CTYPE=C tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= < /dev/random | head -c 20 | xargs
i=$[$i+1]
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment