Re: Random Number Generators....



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



Relevant Pages

  • 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: Calibration curve
    ... I hop eyou used the sum of the square of the distances to get the error. ... Signa is the width of the normal distribution curve. ... The distance becomes your error. ...
    (microsoft.public.excel.misc)
  • 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: can anyone tell me a little about this puzzle - quartering squares & the pythagorean the
    ... approximation to the diagonal of a square, constructed by dividing the ... "saves" any distance traveling between opposite corners versus ... you've traveled a distance of two. ...
    (sci.math)
  • 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)