Generate random float number in given specific range of numbers using Bash Generate random float number in given specific range of numbers using Bash linux linux

Generate random float number in given specific range of numbers using Bash


If you have GNU coreutils available, you could go with:

seq 0 .01 1 | shuf | head -n1

Where 0 is the start (inclusive), .01 is the increment, and 1 is the end (inclusive).


Without any external utilities, generate random real between 3 and 16.999:

a=3b=17echo "$((a+RANDOM%(b-a))).$((RANDOM%999))"


To generate 1 random floating point number between 3 and 17:

$ awk -v min=3 -v max=17 'BEGIN{srand(); print min+rand()*(max-min+1)}'16.4038

To generate 5 random floating point numbers between 3 and 17:

$ awk -v min=3 -v max=17 -v num=5 'BEGIN{srand(); for (i=1;i<=num;i++) print min+rand()*(max-min+1)}'15.10674.792383.0488411.364715.1132

Massage to suit.