How to generate random number in Bash?

前端 未结 11 1494
青春惊慌失措
青春惊慌失措 2020-11-27 09:33

How to generate a random number within a range in Bash?

11条回答
  •  孤城傲影
    2020-11-27 10:15

    If you are using a linux system you can get a random number out of /dev/random or /dev/urandom. Be carefull /dev/random will block if there are not enough random numbers available. If you need speed over randomness use /dev/urandom.

    These "files" will be filled with random numbers generated by the operating system. It depends on the implementation of /dev/random on your system if you get true or pseudo random numbers. True random numbers are generated with help form noise gathered from device drivers like mouse, hard drive, network.

    You can get random numbers from the file with dd

提交回复
热议问题