How to Generate random number in Linux

Generate random number in Linux, How to Generate random number in Linux, GTechHub

How to generate random number in Linux? You can easily generate random numbers with the custom limit range by using shuf command.

shuf is a UNIX and Linux command for generating random permutations.

Syntax for Generate random number in Linux

shuf [INPUT RANGE] [HEAD COUNT]
Generate random number in Linux, How to Generate random number in Linux, GTechHub

Example

The below example will return 7 digits random number. You can change the input range as your requirement.

  • You need to pass input range as “000-999” to get 3 digit number
  • You need to pass input range as “0000-9999” to get 4 digit number
  • You need to pass input range as “00000-99999” to get 5 digit number
  • You need to pass input range as “000000-999999” to get 6 digit number
shuf -i 0000000-9999999 -n 1

Result

73893336

Generate random number in Linux, How to Generate random number in Linux, GTechHub

You Might Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *