Some example code.

Robert Lee robert.lee at chicago.vc
Sat Nov 3 18:44:10 GMT 2012


Excellent point... time for some bit twiddling.

On Sat, 2012-11-03 at 17:16 +0000, Paul Martin wrote:
> 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).
> 





More information about the EntropyKey-users mailing list