<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/4.4.4">
</HEAD>
<BODY>
<B>Silly bash version:</B><BR>
<BR>
<TT>function r {</TT><BR>
<TT>  n=$1</TT><BR>
<TT>  w=`echo "l($n)/l(2)/8+1" | bc -l | cut -d. -f1`</TT><BR>
<TT>  h=`od -N $w -A n -t x1 </dev/random | tr -d '[:space:]' | tr -s '[a-f]' '[A-F]'`</TT><BR>
<TT>  n1=`echo "obase=16;$n" | bc`</TT><BR>
<TT>  echo "scale=0;ibase=16;$h%$n1" | bc</TT><BR>
<TT>}</TT><BR>
<BR>
<B>Command line examples:</B><BR>
<I>r 4298745432987523894</I><BR>
<I>6338443941628</I><BR>
<BR>
<I>r 4298745432987523894</I><BR>
<I>1620597564459386235</I><BR>
<BR>
<I>r 5</I><BR>
<I>0</I><BR>
<BR>
<I>r 5</I><BR>
<I>4</I><BR>
<BR>
<BR>
<BR>
<BR>
On Fri, 2012-11-02 at 21:22 +0000, Paul Martin wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
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
<A HREF="mailto:EntropyKey-users@lists.simtec.co.uk">EntropyKey-users@lists.simtec.co.uk</A>
<A HREF="http://lists.simtec.co.uk/cgi-bin/mailman/listinfo/entropykey-users">http://lists.simtec.co.uk/cgi-bin/mailman/listinfo/entropykey-users</A>
</PRE>
</BLOCKQUOTE>
<BR>
</BODY>
</HTML>