I'm in the process of setting up a local (i.e. offline and very limited) business, and I'm thinking of generating invoice IDs randomly to avoid the clients knowing that they're customer number #00000001 (and because I prefer something like #30549805 to CLIENT1). I've come across the following script to do this:
#!/usr/bin/env bash
digits=8
rand=$(od -A n -t d -N 2 /dev/urandom |tr -d ' ')
num=$((rand % 10))
while [ ${#num} -lt $digits ]; do
rand=$(od -A n -t d -N 1 /dev/urandom |tr -d ' ')
num="${num}$((rand % 10))"
done
echo $num
...and it seems to work well enough: returning 26 duplicates (13 pairs) in more than 55,000 numbers.
Would it be safe to use something like this to generate invoices, and are there any disadvantages to doing so?
Assuming it is safe, what's the lowest amount of digits I can make the ID before the odds of collisions would be too high?