LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Random number generation

I have some old borrowed code that I use to generate many thousands of random
numbers (investment returns) from a normal distribution, given a mean and
standard deviation. It works, except that the sequences aren't really random
and I often see the same numbers over and over. I know that the RAND()
function was updated to increase randomness, but I'm using VBA's RND
function. Does anyone know a way to increase the randomness of the returns
produced by this code?

Sub Getreturn
'where SD is std dev, meanarith is mean arithmetic return

Retn = gauss * SD + meanarith
End Sub

Function gauss()
Dim fac As Double, rt As Double, V1 As Double, V2 As Double
10 V1 = 2 * Rnd - 1
V2 = 2 * Rnd - 1
rt = V1 ^ 2 + V2 ^ 2
If (rt = 1) Then GoTo 10
fac = Sqr(-2 * Log(rt) / rt)
gauss = V2 * fac
End Function


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help for Random Number Generation krisinvincible Excel Worksheet Functions 3 May 7th 07 12:41 AM
random number generation Ahmad Excel Discussion (Misc queries) 3 November 6th 06 06:27 PM
random number generation scotjo Excel Worksheet Functions 4 January 9th 06 04:06 PM
random number generation DSpec Excel Worksheet Functions 7 October 3rd 05 01:41 PM
I need help with random number generation David Stoddard Excel Worksheet Functions 10 March 28th 05 07:06 AM


All times are GMT +1. The time now is 08:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"