Alex Rivera | Logout

When using random, which form returns an equal 50% chance?

Asked 2009-02-26T16:15:37.837
15

I'm guessing that most built in random generators return something like this:

[0.0, 1.0)

so if I would like a 50% chance would I use something like this:

if random() < .5

or something like:

if random() <= .5

Thanks for the help.

Edit
Report

3 Answers

1

For a particular system you should test it, if you really want to find out. Could take a while though :-)

I agree with the other posters that to the first order, it doesn't matter. If it does matter, you'll need a better RNG anyway.

EDIT: I just tried the default RNG in C# with 1,000,000,000 attempts and the answers were identical...

answered 2009-02-26T16:39:14.177
0
< .5

but that assumes that your floating point support is good enough to satisfy your precision demands (since it's never exactly).

answered 2009-02-26T16:21:19.913
-1

It doesn't matter. Both formulas yield the desired result.

answered 2009-02-26T16:19:19.543

Your Answer