POV-Ray : Newsgroups : povray.programming : random numbers in c++ : Re: random numbers in c++ Server Time
26 Apr 2024 01:39:08 EDT (-0400)
  Re: random numbers in c++  
From: Anthony D  Baye
Date: 25 Aug 2010 18:55:00
Message: <web.4c759e94377bc0d7507e8a090@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Am 25.08.2010 18:38, schrieb Anthony D. Baye:
>
> >> First, note that rand() /is/ uniformly distributed, in the interval 0 to
> >> RAND_MAX (which, BTW, is typically 32767, but you shouldn't rely on that).
> >
> > this has not been my experience.  printing the result of one million calls to
> > rand() gives numbers up to ten digits long, but I've never seen a result less
> > than six digits in length.  If every result were equally likely, there should be
> > SOME lower numbers in the batch, shouldn't there?
>
> Okay, let me rephrase that:
>
> "... rand() /is/ _supposed_ to be uniformly distributed..."
>
> According to ANSI-C standard, the actual implementation of rand() is
> implementation-specific, and is known to be poor in typical
> implementations. The maximum number returned - RAND_MAX - is
> implementation-specific as well, and is specified to be at least 32767.
> According to Microsoft documentation, their C runtime library has
> RAND_MAX=32767, though I haven't actually bothered to test it.

At any rate, the solution suggested by Le Forgeron, using drand48(), seems to
work.

There are still a few issues, however.

The chief problem is thatsuccessive calls to the program return the same result
every time.

The only way I've found to change the result is to modify the initial conditions
(i.e. changing the number of seed values in the grid before calling the
Diamond_Square() function.)

Thanks for the input, so far.

A.D.B.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.