strange problems with Random

• To: mathgroup at smc.vnet.net
• Subject: [mg47812] strange problems with Random
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Tue, 27 Apr 2004 04:48:05 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Recently Mark Coleman wrote a message with the subject "Differences in
Random Numbers" in which he described his experience of getting
Random[UniformDistribution[0,1]] instead of simple Random[]. Jens Kuska
and Bill Rowe pointed out that the package  ContinuousDistributions
contains the code

UniformDistribution/: Random[UniformDistribution[min_:0, max_:1]] :=
Random[Real, {min, max}]

and that seemed to be it. However, I have now encountered a problem
that makes me feel strongly that there is more to this problem than it
seemed to me at first.

I have been doing some Monte Carlo computations of values of of
financial options for the Internet based course on this subject I am
teaching for Warsaw University.  In the case of the simplest options,
the so called vanilla european options, an exact formula (due to black
and Scholes) is known. Neverheless, computations with Mathematica using
the function

Random[NormalDistribution[mu,sigma]] (for some fixed mu and sigma) have
been giving answers which are consistently higher than the
Black-Scholes value. On the other hand, when
Random[NormalDistribution[mu,sigma]]  is replaced by the following code
using a well known algorithm due to Marsaglia:

RandomNormal=Compile[{mu, sigma}, Module[{va = 1., vb, rad =
2.0, den = 1.}, While[rad ³ 1.00, (va = 2.0*Random[] - 1.0;
vb = 2.0*Random[] - 1.0;
mu + sigma*va*den]];

the answers agree very closely with the Black-Scholes ones.
I am not sure if this problem is related to the one mark mentioned but
it seems quite likely.  One could in principle test it by replacing
Statistics`ContinuousDistributions`) package, but if one does that the
code will no longer compile. That makes the function to slow for tests
that are sufficiently precise, so I have not tested it.

In any case, I am sure that using Random[Normal  ] consistently gives
wrong answers. I looked at the Statistics`NormalDistributionPackage`
but everything looks O.K. to me. I now tend to believe that the problem
lies with Random itself, that is that  Random called with any
parameters or perhaps some particular parameters may not be behaving
correctly. Random[] called with no parameters does not seem to  suffer
from any such problems.

Andrzej Kozlowski
Chiba, Japan
http://www.mimuw.edu.pl/~akoz/

```

• Prev by Date: RE: Question on pattern matching
• Next by Date: Re: Re: bug in IntegerPart ?
• Previous by thread: RE: i don't understand mapping function over a long list
• Next by thread: Re: strange problems with Random