MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Troubling Bug involving RandomReal, NestList, and Table


On Mar 7, 2:48 am, Szabolcs Horv=E1t <szhor... at gmail.com> wrote:
> jwmerr... at gmail.com wrote:
> > When making tables of 250 or more directions, Mathematica seems to
> > forget how to do arithmetic.  I realize these "random" directions are
> > not properly uniform, but that's beside the point.

> > randomDirection3[] :=
> >  NestList[Sqrt[1 - #^2] &, RandomReal[], 1]

> > Variance[Table[Norm[randomDirection3[]], {249}]]
> > Variance[Table[Norm[randomDirection3[]], {250}]]
>
> >> 1.49104*10^-33
> >> 0.0513843


> One workaround that you could use (without giving up compilation) is this:=

>
> cp = Compile[{}, With[{r = Random[]}, {r, Sqrt[1 - r^2]}]]
>
> (But I am sure you already found many other ways around the problem.)
>
> Szabolcs

Thanks to all for your explanations and advice.  My eventual solution
(pilfered from elsewhere on the internet), was

randomUnitVector[dimensions_] :=
 Normalize[RandomReal[NormalDistribution[], dimensions]]

Regards,

JM



  • Prev by Date: Re: Re: Apply function to parts of a list
  • Next by Date: Re: Evaluating notebooks from other notebooks
  • Previous by thread: Re: Troubling Bug involving RandomReal, NestList, and Table
  • Next by thread: How to introduce new hot keys?