Re: Random Number Generators....




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.

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

Uh, what went wrong?



Richard

.



Relevant Pages

  • Re: Random Number Generators....
    ... That sqrt() is not absolutely needed there, if you choose to discard it you ... can get rid of too. ... must the square of that number be? ...
    (comp.lang.c)
  • Sony WEGA TV problem
    ... I can't get rid of the on-screen AV channel indicator. ... I've tried the button with the cross inside a square, ... some other screen options. ...
    (sci.electronics.repair)
  • Re: Random Number Generators....
    ... can get rid of too. ... of how to determine distance without using sqrt. ... how big the square of a number <1 must be doesn't cut it. ... He said "that sqrt() is not absolutely needed there". ...
    (comp.lang.c)
  • Re: Random Number Generators....
    ... can get rid of too. ... of how to determine distance without using sqrt. ... how big the square of a number <1 must be doesn't cut it. ... He said "that sqrt() is not absolutely needed there". ...
    (comp.lang.c)
  • Re: Marlett font
    ... Marlett displays a small square when there is no specific symbol ... The way to get rid of it, therefore, is to select the square character ... and change the font to a normal one. ...
    (microsoft.public.word.newusers)