Random String in linux by system time -


i work bash. want generate randrom string system time . length of unique string must between 10 , 30 characters.can me?

there many ways this, favorite 1 using urandom device:

burhan@sandbox:~$ tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1 cci4zgdq0sobfap9k0xeuisjo9ujmt 
  • tr (translate) makes sure alphanumerics shown
  • fold wrap 30 character width
  • head makes sure first line

to use current system time (as have specific requirement):

burhan@sandbox:~$ date +%s | sha256sum | base64 | head -c30; echo ndc0ngqxzdq4mwninzbjy2eyngflow 
  • date +%s = our date based seed
  • we run through few hashes "random" string
  • finally truncate 30 characters

other ways (including 2 listed above) available @ this page , others if google.


Comments