077e8d01a877df6bb30fb90e9c58f1c3604a0dd3
3 #==BEGIN Function Definitions==
5 # Desc: Output random float
6 # Usage: randFloat arg1
7 # Inputs: arg1: number of decimal places
8 # Output: stdout: float as decimal string
10 # Note: Outputs float from 0.000... to 0.999...
11 # Note: Default number of decimals is 5.
12 # Ref/Attrib: Integer test regular expression https://stackoverflow.com/a/806923
15 if [[ $# -eq 0 ]]; then
17 elif [[ $# -eq 1 ]]; then
20 if ! [[ $arg1 =~
$RETEST1 ]]; then
21 echo "ERROR:Not an integer." >&2; exit 1;
24 echo "ERROR:Invalid number of arguments:${@}";
28 decimals
="$(head -c ${arg1:-5} < <(LC_ALL=C tr -cd "[:digit
:]" < <(cat /dev/urandom)))";
29 printf "0.%s\n" "$decimals";
30 }; # output random float [0.00000 1.00000] to stdout
31 #==END Function Definitions==
33 #==BEGIN sample code==
39 time (randFloat
&& randFloat
&& randFloat
&& randFloat
&& randFloat
&& randFloat
&& randFloat
&& randFloat
&& randFloat
&& randFloat
);
40 time (randFloat
"$dec" && randFloat
"$dec" && randFloat
"$dec" && randFloat
"$dec" && randFloat
"$dec" && randFloat
"$dec" && randFloat
"$dec" && randFloat
"$dec" && randFloat
"$dec" && randFloat
"$dec");
41 time (randFloat
"$dec" &>/dev
/null
&& randFloat
"$dec" &>/dev
/null
&& randFloat
"$dec" &>/dev
/null
&& randFloat
"$dec" &>/dev
/null
&& randFloat
"$dec" &>/dev
/null
&& randFloat
"$dec" &>/dev
/null
&& randFloat
"$dec" &>/dev
/null
&& randFloat
"$dec" &>/dev
/null
&& randFloat
"$dec" &>/dev
/null
&& randFloat
"$dec" &>/dev
/null
);