[bigint] (Big integer random-number generator)

Matt McCutchen <matt at mattmccutchen.net>
Fri Apr 16 07:43:02 PDT 2010


On Thu, 2010-04-15 at 19:13 +0000, Nicolas Carrasco wrote:
> I need an BigUnsigned uniform random generator, do you know where I
> can find one implementation that uses your Bin Integer Library?
> 
> For example I need to generate random numbers with an uniform
> distribution from:
> 1 to
> 52198620942407957076910735856809911895553771388490307930972455149942
> in order to generate Boolean functions from an Enumerative
> Codification.

I don't know of any random number generator for my big integers.  You
could probably write one yourself without too much trouble.  Just call
an ordinary random number generator for each block, convert the blocks
to a BigUnsigned with the "BigUnsigned(const Blk *b, Index blen)"
constructor, and then start over if the resulting number is above the
upper limit.  This way you get a uniform distribution.

A random number generator might be something worth adding to the library
itself, except that I'm not sure if there is a portable source of
randomness that will meet everyone's needs.  I guess I could write a
random number generator that uses a callback to generate the individual
blocks.

-- 
Matt




More information about the bigint mailing list