Demonstrates techniques for generating unique ids in scripts.
TODO:
- crypto hash
- nanoid https://github.com/ai/nanoid
# macosx
uuidgen# install uuidgen on debian
apt-get install uuid-runtime
uuidgendate +%s
# macosx
$ date -r 1282368345
Sat Aug 21 07:25:45 CEST 2010
$ date -r 1282368345 +%Y-%m-%d
2010-08-21
$ date -d @1282368345
Sat Aug 21 07:25:45 CEST 2010
$ date -d @1282368345 --rfc-3339=date
2010-08-21# random number
echo $RANDOM
# random number between 1 and 10
echo "$(( ( RANDOM % 10 ) + 1 ))"LC_CTYPE=C tr -dc A-Za-z0-9 < /dev/random | head -c 60 | xargs
# or
head /dev/urandom | tr -dc a-f0-9 | head -c 40This technique can be used for consistent hashing
# take a string and cksum it.
echo $(echo "hashingstring" | cksum | cut -f 1 -d \ )head /dev/urandom | tr -dc a-f0-9 | head -c 40- /dev/random example here
- nodejs uuid-support-in-the-crypto-module