Some example code.

Paul Martin pm at simtec.co.uk
Sat Nov 3 17:16:34 GMT 2012


On Fri, Nov 02, 2012 at 08:24:29PM -0500, Robert Lee wrote:
> Silly bash version:
> 
> function r {
>   n=$1
>   w=`echo "l($n)/l(2)/8+1" | bc -l | cut -d. -f1`
>   h=`od -N $w -A n -t x1 </dev/random | tr -d '[:space:]' | tr -s
> '[a-f]' '[A-F]'`
>   n1=`echo "obase=16;$n" | bc`
>   echo "scale=0;ibase=16;$h%$n1" | bc
> }

This has the problem of uneven distribution where the random source
has returned a value (>= n*x) close to the maximum value, where x is
such that n*x < MAX < n*(x+1)

The code I posted discards any source values >= n*x... and does it
without detecting overflows (an unreliable trick).

-- 
Paul Martin <pm at simtec.co.uk>
Simtec Electronics         Tel: +44 1772 978010
http://www.simtec.co.uk/   Fax: +44 1772 816426



More information about the EntropyKey-users mailing list