How to get a random string of 32 hexadecimal digits through command line?

后端 未结 5 638
暗喜
暗喜 2021-01-31 14:00

I\'d like to put together a command that will print out a string of 32 hexadecimal digits. I\'ve got a Python script that works:

python -c \'import random ; prin         


        
5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-31 14:39

    There three ways that I know of:

    #!/bin/bash
    
    n=16 
    
    # Read n bytes from urandom (in hex):
    xxd -l "$n" -p                    /dev/urandom | tr -d " \n" ; echo
    od  -vN "$n" -An -tx1             /dev/urandom | tr -d " \n" ; echo
    hexdump -vn "$n" -e ' /1 "%02x"'  /dev/urandom ; echo
    

    Use one, comment out the other two.

提交回复
热议问题