-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom-nid
executable file
·41 lines (39 loc) · 967 Bytes
/
random-nid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh
set -euf
##
# Generate a secure random numeric id
#
# Usage:
#
# random-nid
#
# Example:
#
# random-nid
# #=> 8125681425681428762
#
# The term "nid" is our shorthand for secure
# random numeric id that uses digits 1-8,
# exactly 19 times.
#
# This has desireable properties:
#
# * All numbers are the same length
# * No leading zero
# * Fits in an 8-byte integer representation
# * Translatable to octal if need.
#
# This implementation uses `/dev/urandom`
# and `tr` to select matching characters.
#
# Depending on your own systems and security needs,
# you may want to adjust this script by changing the
# system command `/dev/urandom` to `/dev/urandom`.
# This change will make the script non-blocking.
#
# Contact: Joel Parker Henderson (joel@joelparkerhenderson.com)
# License: BSD or MIT or GPL or contact us for custom license
# Updated: 2021-10-14T17:58:40Z
##
len=19
LC_ALL=C < /dev/urandom tr -dc "12345678" | head -c"$len"