[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Generating "independent" random numbers
From: |
Keith Wright |
Subject: |
Re: Generating "independent" random numbers |
Date: |
Wed, 04 Oct 2023 12:14:06 -0400 |
From: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
> my goal is normal distributed floats (leaving aside the finite
> nature of the computer and floats).
Warning: I am out of my depth, I can't even spell statisticion, but...
The following is either provably correct up to round-off,
or totally stupid.
First define the cumulative distribution for the normal distribution:
$$f(x)= \frac{1}{\sqrt{\pi}} \int_{-\infty}^{x} e^{-x^2/2} dx $$
Now to get a normal random variable, let $u$ be a uniform random number
on [0,1), then $f^{-1}(u)$ is a standard normal random variable.
Computing the inverse of the cumulative normal distribution is left as
an exercise, because I don't know how, but it seems possible.
From: Maxime Devos <maximedevos@telenet.be>
> So, to generate an (approximately) uniform random number on [0,1), you
> can simply do
>
> (define (random-real)
> (exact->inexact (/ (random N) N)))
>
> for a suitably large choice of integer N>0.
A choice that makes this nice (on a 32 bit machine) is $N = 2^{32}$.
-- Keith