3 ms·
I figured it had small cases down so I immediately went for a fifteen digit number from /dev/urandom and was happy that it solved it perfectly. But I'm probably
by lucb1e 8y ago
I figured it had small cases down so I immediately went for a fifteen digit number from /dev/urandom and was happy that it solved it perfectly. But I'm probably the exception.
For those wondering how to generate random numbers, it's simple if you don't care about a little computational overhead: </dev/urandom tr -dc 0-9 | head -c 15 (substitute 0-9 for any character set like a-zA-Z or \ -~). I use this to generate random PIN numbers after it took too long to read the pwgen man page, and I might start to use it as replacement for pwgen altogether since it only uses very basic tools that are available everywhere, unlike pwgen.
To explain the command: we read urandom into tr's stdin; tr translates (like "echo haha | tr a u"); with -d, tr deletes instead of substituting; with -c, it takes the compliment set (so everything except what you specify). Basically we're filtering characters or of urandom's output. Finally, we limit the output to a certain number of characters.
- ConceptJunkie 8y agoThe paper gives a detailed algorithm to provide 3 palindrome that add up to the number. The algorithm has tons of cases, but it's actually pretty simple. They work through a couple in the video. It's a cool result.
- EForEndeavour 8y agoCool one-liner to get random digits. On OSX, it produces the error "tr: Illegal byte sequence." The solution, per https://unix.stackexchange.com/q/45404 https://unix.stackexchange.com/q/45404, is to prepend the script with "LC_CTYPE=C ": LC_CTYPE=C </dev/urandom tr -dc 0-9 | head -c 15