Re: Random Number Generation
- From: Michael Mair <Michael.Mair@xxxxxxxxxxxxxxx>
- Date: Wed, 31 May 2006 08:21:13 +0200
Eric schrieb:
Eric Sosman wrote:Eric wrote On 05/19/06 20:40,:Richard Heathfield wrote:muttaa said:
May i know how to write a code that generates random numbers as many
times as one would want ? i.e. like the standard function 'rand()' or
may i get the basic logic behind it ?
One common technique is the Linear Congruential PseudoRandom Number
Generator. This works on the principle of taking a "current"
pseudo-random value r and three constants, a, c, and m, and producing the
next pseudo-random number by this method:
r = (a * r + c) % m;
How good this generator is depends largely on your choices for a, c, and
m (and, of course, other factors, such as the range of r).
interesting.
m would be rand_max-1 i think
a and c would be prime numbers maybe? (well, that was my choice)
and initial value of r would be the seed.
I played with this once i saw your post and it seems quite workable
as a pseudo random generator. Its also extremely easy to implement.
I love little tidbits like this!
From your speculations about appropriate values for
m, a, and c, it is clear that you have no knowledge at
all about what they should be. You therefore deserve
the Bad Things that are likely to happen to you if you
decide to implement any such "little tidbit." Alas, it
is only too likely that you will code it into a program
someone else will use, thus inflicting your ignorance
upon innocent bystanders.
If you can't be bothered to do any research at all,
there's no hope. But in hope you can be persuaded to
lift a finger five times and make a few mouse clicks,
I offer one word: RANDU.
Jesus Man, take a fucking chill pill will ya? Its not the end of the world
you know.
Well, if your PRNG based on the above is used, the outcome
may be severely skewed -- you do not generate RAND_MAX-1 and
RAND_MAX and there may be numbers that cannot be reached by
your choice of a and c. Example: m % c == 0 and start at some
r with r % c == 0. Statistic experiments based on that are
obviously flawed.
Depending on where you spread or abuse your "knowledge", you
may be able to cause some damage. Even a little dose of
number theory or thought can prevent that. For a high quality
PRNG, you need more background (period, distribution of the
values, distribution modulo certain values, n-dimensional
distribution to name but a few).
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
.
- References:
- Random Number Generation
- From: muttaa
- Re: Random Number Generation
- From: Richard Heathfield
- Re: Random Number Generation
- From: Eric
- Re: Random Number Generation
- From: Eric Sosman
- Re: Random Number Generation
- From: Eric
- Random Number Generation
- Prev by Date: Re: Simplicity has a future
- Next by Date: Re: Simplicity has a future
- Previous by thread: Re: Random Number Generation
- Next by thread: Re: Random Number Generation
- Index(es):