Some example code.

Robert Lee robert.lee at chicago.vc
Sat Nov 3 01:24:29 GMT 2012


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
}

Command line examples:
r 4298745432987523894
6338443941628

r 4298745432987523894
1620597564459386235

r 5
0

r 5
4




On Fri, 2012-11-02 at 21:22 +0000, Paul Martin wrote:

> I was looking into a customer query earlier today, and came up with
> the following which might be useful to people.
> 
> It's crude, but it demonstrates how you might transform entropy from a
> byte source into random integers between 0 and n-1.
> 
> _______________________________________________
> EntropyKey-users mailing list
> EntropyKey-users at lists.simtec.co.uk
> http://lists.simtec.co.uk/cgi-bin/mailman/listinfo/entropykey-users


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.simtec.co.uk/pipermail/entropykey-users/attachments/20121102/ea621b05/attachment.html>


More information about the EntropyKey-users mailing list