Hmm, actually, that doesn't give numbers in the right range because of
the way the remainder is handled. You could round up the remainder to
the nearest power of two and then generate random coefficients using
rejection sampling but that's not as nice as a closed form solution.
Probably any of the textbook algorithms for generating
non-power-of-two random numbers from random bit streams should apply
to this kind of situation.

-Per

On Sat, May 1, 2010 at 8:48 PM, Per Vognsen <per.vogn...@gmail.com> wrote:
> On Sat, May 1, 2010 at 7:25 PM, Lee Spector <lspec...@hampshire.edu> wrote:
>> about how to write a real random bignum generator.
>
> Let n be the bignum upper bound on the desired range. Find the
> quotient q and remainder r of n by b = 2^31-1. Generate q random
> numbers with upper bound b and one random number with upper bound r.
> Now use Horner's method to reconstruct a random bignum from these
> random fixnum parts with q additions and multiplications.
>
> This is adding uniformly distributed random variables with disjoint
> but abutting ranges. Therefore the sum is again a uniform random
> variable.
>
> -Per
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to