Re: Random Number Generators....
- From: "mensanator@xxxxxxx" <mensanator@xxxxxxx>
- Date: 28 Feb 2006 09:50:48 -0800
Richard Bos wrote:
"mensanator@xxxxxxx" <mensanator@xxxxxxx> wrote:
stathis gotsis wrote:
"RadiationX" <heavyreader@xxxxxxxxx> wrote in message
news:1141079204.141032.9090@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
{
double x;
double y;
x = (double)rand()/RAND_MAX;
y = (double)rand()/RAND_MAX;
if((sqrt(x*x + y*y)<=1.0))
That sqrt() is not absolutely needed there, if you choose to discard it you
can get rid of <math.h> too.
How?
If a non-negative real number is smaller than or equal to 1.0, how large
must the square of that number be?
Oh, I get it.
x = 0.9
If the x coordinate is less than 1, its square is less than 1.
y = 0.9
And if the y coordinate is less than 1, its square is less than 1.
So if the squares of both are less than 1, then the distance
from the origin is less than 1.
1.27279220614print math.sqrt(x**2 + y**2)
Uh, what went wrong?
Richard
.
- Follow-Ups:
- Re: Random Number Generators....
- From: Jordan Abel
- Re: Random Number Generators....
- References:
- Random Number Generators....
- From: RadiationX
- Re: Random Number Generators....
- From: Keith Thompson
- Re: Random Number Generators....
- From: RadiationX
- Re: Random Number Generators....
- From: RadiationX
- Re: Random Number Generators....
- From: RadiationX
- Re: Random Number Generators....
- From: mensanator@xxxxxxx
- Re: Random Number Generators....
- From: RadiationX
- Re: Random Number Generators....
- From: mensanator@xxxxxxx
- Re: Random Number Generators....
- From: Keith Thompson
- Re: Random Number Generators....
- From: RadiationX
- Re: Random Number Generators....
- From: stathis gotsis
- Re: Random Number Generators....
- From: mensanator@xxxxxxx
- Re: Random Number Generators....
- From: Richard Bos
- Random Number Generators....
- Prev by Date: Re: need help getting the results of the system function into a variable
- Next by Date: Re: what is wrong with this
- Previous by thread: Re: Random Number Generators....
- Next by thread: Re: Random Number Generators....
- Index(es):
Relevant Pages
|
|