this is my problem: I have to generate random numbers, using VBA, from
different distribution functions... Rand (and randomize...) generates
numbers only from a "Uniform distribution" (well... Microsoft says that it's
a "pseudo-uniform" distribution, but this isn't a problem...). How can
ganerate numbers from a Normal (=Gaussian) and a Exponential distribution
using VBA?
Thank you in advance...
Bye Attilio.
=$A$1+$A$2*(((-2*LN(RAND()))^0.5)*COS(2*PI()*RAND()))
Cell A1 would contain the Mean or average while cell A2 would contain the
desired standard deviation or Sigma. You can copy this down a column to
get a normal random distribution.
Hope this helps.
Don't know how to do an exponential.
"Attilio Gelosa" <attili...@libero.it> wrote in message
news:a0uhkl$n3ohf$1...@ID-59998.news.dfncis.de...
=norminv(rand(),mean,stdev) for a normal variate, and
=-ln(1-rand())/lambda for an exponential variate.
(Generally, if F(x) is the cumulative distribution of the desired variate,
F[inverse](rand()) will simulate the variate itself.)
- Bob
"Attilio Gelosa" <attili...@libero.it> wrote in message
news:a0uhkl$n3ohf$1...@ID-59998.news.dfncis.de...
Sub Demo()
' Dana DeLouis
Const FxRandom As String = "ATPVBAEN.XLA!Random"
Const NormalDistribution As Long = 2
Const Mean As Double = 0 'Mean
Const SD As Double = 1 'Standard Dev
Dim OutRange As Range
Set OutRange = [A1:A10]
[OutRange].ClearContents
Application.Run FxRandom, OutRange, , , NormalDistribution, , Mean, SD
End Sub
--
Dana DeLouis Windows Me & Office XP
"Attilio Gelosa" <attili...@libero.it> wrote in message
news:a0uhkl$n3ohf$1...@ID-59998.news.dfncis.de...
NormInv() and NormSInv() are particularly poor (in Excel versions prior
to XP), and will generate an unacceptably large fraction of "normal
random numbers" that are several million standard deviations away from
the mean!
Jerry
HTH
--
Nico Sterk
Venuslaan 71
5632 HA Eindhoven
Netherlands
+31 40 242 9317
+31 6 29 10 70 15
n.s...@chello.nl
http://members.tripodnet.nl/excelsoftware
"Attilio Gelosa" <attili...@libero.it> wrote in message
news:a0uhkl$n3ohf$1...@ID-59998.news.dfncis.de...
--
Nico Sterk
Venuslaan 71
5632 HA Eindhoven
Netherlands
+31 40 242 9317
+31 6 29 10 70 15
n.s...@chello.nl
http://members.tripodnet.nl/excelsoftware
"Attilio Gelosa" <attili...@libero.it> wrote in message
news:a0uhkl$n3ohf$1...@ID-59998.news.dfncis.de...
Regards,
Dave Braden
In article <3C332828.2070302@no_e-mail.com>, Jerry W. Lewis
<post_a_reply@no_e-mail.com> wrote:
--
FAQ and other goodies: http://www.cpearson.com/excel/newposte.htm
More FAQs: http://j-walk.com/ss/excel/faqs/index.htm
More info and links: http://j-walk.com/ss/
Regards,
Dave Braden
In article <OPV6dg5kBHA.2080@tkmsftngp07>, Dana DeLouis
<ng_...@hotmail.com> wrote:
--
1. RAND() is not an adequate approximation to uniform random numbers
2. The improved accuracy to NORMSINV() in Excel XP is still not
adequate, but machine accuracy would be
3. Machine accuracy for RAND() and NORMSINV() still are still too
discrete in the to adequately approximate normal tails
The second potential reason could easily be fixed using the PNormInv
algorithm I posted to microsoft.public.excel.misc in September under
your thread "Normal Distribution"
http://groups.google.com/groups?selm=3BB620CB.40404%40no_e-mail.com
The first potential reason would impact the correlation structure of
multiple "random numbers," and so might cause problems with the
Box-Muller algorithm also. It could be improved with a better
pseudo-random number generator, but the nature of pseudo-random numbers
is that it cannot be completely eliminated.
The third potential reason would likely impact the tails of any
distribution over an infinite or half-infinite range. It might also
impact the Box-Muller algorithm. If this is a significant problem, then
alternate approaches, such as Marsaglia's ziggurat method
http://www.jstatsoft.org/v05/i08/
would need to be used for converting uniform random numbers into other
distributions.
Jerry