Search code examples
macos

Get random number on command line on MacOs (like shuf)


I need add random number to filename. On Linux I use command like

filename$(shuf -i 10000000-99999999 -n 1)

But on MacOs with this command I recieve error:

sh: shuf: command not found

Here are another solution on MacOs for make it?


Solution

  • Like this maybe:

    dd bs=4 count=1 if=/dev/urandom 2>/dev/null | xxd -p 
    7bfe4143
    

    Or with od:

    head -c 4 /dev/urandom | od -An -tu4
    2465874330
    

    Or with bash's $RANDOM:

    echo $RANDOM$RANDOM
    820227815