DEV Community

Discussion on: Write a simple but impactful script

Collapse
 
jacaetevha profile image
Jason Rogers †

Just coming across this. I like finding and using old gems. For this, jot does just great.

jot -w %04d 9999 | shuf > /path/to/pins.txt

Or for those on a Mac using GNU coreutils (probably from brew), you'd use gshuf instead of shuf:

jot -w %04d 9999 | gshuf > /path/to/pins.txt

Of course, Ruby is just as elegant:

ruby -e 'puts ("0000"..."9999").to_a.shuffle' > /path/to/pins.txt

... but on my machine the Ruby solution is about 95% slower than the jot version: 148ms vs. 8ms, respectively.