Create list of random numbers

# Echo $1 random numbers between zero and $2. e.g. echo $(rand 8 32)
function rand {
    declare -i rand_1
    declare -i rand_2
    rand_2=$(($1*4))
    for rand_1 in $(od -vAn -N${rand_2} -tu4 < /dev/urandom); do echo $(($rand_1%$2));done
}

... for example ...

# See list_to_data in previous post.
list_to_data $(rand 100 32)
echo ${data[@]}
19 9 27 23 25 16 11 16 5 4 7 3 1 10 29 9 23 4 27 19 9 2 17 12 9 0 27 30 15 12 14 16 26 7 8 31 10 28 20 21 18 26 9 4 24 2 21 1 28 23 30 18 7 2 30 1 26 30 0 13 24 23 28 23 19 31 29 6 17 8 17 0 18 26 30 1 19 30 3 29 6 15 8 14 18 12 3 24 19 10 16 7 2 28 18 4 19 11 0 19

Comments

Popular posts from this blog

oche, lik echo but a bit easier to use.

Bithon: Run Python Interactively Inside Bash

Parsing Columns From Files WITHOUT awk