Re: Random Number Generators....
- From: Jordan Abel <random832@xxxxxxxxx>
- Date: 28 Feb 2006 19:27:27 GMT
On 2006-02-28, mensanator@xxxxxxx <mensanator@xxxxxxx> wrote:
Jordan Abel wrote:
On 2006-02-28, mensanator@xxxxxxx <mensanator@xxxxxxx> wrote:
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.
True.
y = 0.9
And if the y coordinate is less than 1, its square is less than 1.
True.
So if the squares of both are less than 1, then the distance
from the origin is less than 1.
False.
1.27279220614print math.sqrt(x**2 + y**2)
Uh, what went wrong?
The distance from the origin is 1.27. Hint: the distance from the origin
being less than one is determined by being inside the unit _circle_, not
the unit square.
Yeah, _I_ know that. I'm waiting to hear Richards Bos' explanation
of how to determine distance without using sqrt. The stuff about
how big the square of a number <1 must be doesn't cut it.
But you're not looking at the square of X and the square of Y - you're
looking at the square of the distance, which is the sum of those two
squares.
.
- 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
- Re: Random Number Generators....
- From: mensanator@xxxxxxx
- Re: Random Number Generators....
- From: Jordan Abel
- Re: Random Number Generators....
- From: mensanator@xxxxxxx
- Random Number Generators....
- Prev by Date: Re: Random Number Generators....
- Next by Date: Launch of User Interface Community
- Previous by thread: Re: Random Number Generators....
- Next by thread: Re: Random Number Generators....
- Index(es):
Relevant Pages
|
|