On Fri, Aug 28, 2015 at 11:01:45AM +0200, Martijn van Duren wrote:
> Here's some potential useful feature from my .profile. It might not be
> perfect, but at least it's better then some of the generators I've seen in
> production.
>
> # $RANDOM is not portable and in ksh it's limited to 32767.
> rand() {
>       local number
>       local rdevice
>
>       for rdevice in /dev/{u,}random fail; do
>               test -c $rdevice -a -r $rdevice && break
>       done
>       test $rdevice = "fail" && return 1
>
>       number=$(dd if=$rdevice bs=4 count=1 2>/dev/null | hexdump -e '/4 
> "%u\n"')
>       if [ -z "$1" ]; then
>               echo $number
>       else
>               echo $(($number % $(($1 + 1))))
>       fi
> }

One can use 'openssl rand' here for results of the same quality in
less lines.

--
Matthieu Herrb

[demime 1.01d removed an attachment of type application/pgp-signature]

Reply via email to