Re: Random Number Generators....



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.


print math.sqrt(x**2 + y**2)
1.27279220614

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.
.



Relevant Pages

  • Re: Random Number Generators....
    ... Richard Bos wrote: ... That sqrt() is not absolutely needed there, if you choose to discard it you ... If the x coordinate is less than 1, its square is less than 1. ... The distance from the origin is 1.27. ...
    (comp.lang.c)
  • Re: Plain English Djikstra - help??
    ... On a real-life map, thsi makes sense - there are discrete distances ... The problem is you can only fill one square as a time, ... We will use a queue, and I will explain the difference later. ... the distance "one step" larger (where the step is the cost of movement ...
    (rec.games.roguelike.development)
  • Re: Perspective not quite correct?
    ... Any point in space gets mapped to the wall using a light ray from that point ... the square in the top left corner would be the same size as the one ... Imagine you have a sheet of glass in front of you and you traced the image ... If you look at one of the little checkers at a corner, it has a distance ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: Ten points in a square
    ... If you place 10 distinct points in a square of side 1, ... two points will have distance no more than sqrt/3. ... It is 0.421..., which follows from the packing of ten unit circles, proven ...
    (sci.math)
  • Re: How many satellites are in geosynchronous orbit by now?
    ... > strength of that echo tends to drop as the inverse of distance squared. ... > distance to the fourth power. ... For anyone who would like further explanation of the inverse square ... For our radar situation, such a diagram could be expanded upon to show ...
    (sci.space.history)