3 #==BEGIN Function Definitions==
5 # Desc: Output random float with no newline
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)))";
31 #==END Function Definitions==
33 #==BEGIN sample code==
36 time (randFloat
&& randFloat
&& randFloat
&& randFloat
&& randFloat
&& randFloat
&& randFloat
&& randFloat
&& randFloat
&& randFloat
);
37 time (randFloat
"$dec" && randFloat
"$dec" && randFloat
"$dec" && randFloat
"$dec" && randFloat
"$dec" && randFloat
"$dec" && randFloat
"$dec" && randFloat
"$dec" && randFloat
"$dec" && randFloat
"$dec");
38 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
);