Random number generation

  • Thread starter gagan.singh.arora
  • Start date
W

websnarf

CBFalconer said:
The simplified linear congruential r = mr % rmax; (the addend is
0). Also those based on polynomials, eg a CRC16 generator.

I didn't say they were good prngs. :)

I wouldn't say they were prngs at all. And I'm not aware of anyone
else calling them that either. As far as I know, all serious PRNGs
will output 0 (or any other value in range) exactly 1/(1+RANDMAX)
proportion of the time.
 
M

Mark McIntyre

On Wed, 6 Dec 2006 00:09:27 +0000 (UTC), in comp.lang.c ,
Sure they are (if they could be randomly generated at all).
They just don't have a uniform distribution.

For some reason I read the OP's requirement as wanting 80% to be even,
and 20% to be odd.
Throw two fair-weighted six-sided dice. The total of the upwards
faces is random in the range 2 to 12 -- but the total will not
have a uniform random distribution. (e.g., 2 and 12 will each have
probability 1/36; 7 will have probability 1/6).

You have two sets of random numbers here. :)

FWIW I know what you're saying. BTW its probably how I'd solve the
OP's problem - generate two sets of random data, and an algo for
weighting them.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
R

Richard Bos

CBFalconer said:
Most (not all) random generators will never generate a zero
(because that value gets them into an infinite loop). If you know
this you can take advantage by conditionally subtracting one after
the odd/even decision.

The Standard rand() can generate values from 0 to RAND_MAX, though.
While I don't think that means that it _must_ sometimes return 0, I'd
consider a version of rand() (or a replacement for it) that didn't to be
poor design. Amongst other reasons, you now have a function which
returns RAND_MAX (usually 2**N-1) values, rather than the expected
RAND_MAX+1 (usually 2**N), i.e. 0 through RAND_MAX.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,616
Members
45,305
Latest member
KetoMeltsupplement

Latest Threads

Top