Hi,
I need this code for some check of Gaussian distribution.
Computer I7, 8GB, 1,36GHz, SSD, Excel 2013Please Login or Register to view this content.
Excel takes not more than 30% of RAM and 20% processor time
What is wrong with it?
Hi,
I need this code for some check of Gaussian distribution.
Computer I7, 8GB, 1,36GHz, SSD, Excel 2013Please Login or Register to view this content.
Excel takes not more than 30% of RAM and 20% processor time
What is wrong with it?
Hi tim,
I'm not surprised... you are asking excel to loop for a trillion iterations, generating a random number each time... that's going to take some time
Aditionally it is holding a significant array in memory while the code runs.
Please help by:
Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know
There are 10 kinds of people in this world... those who understand binary, and those who don't.
What's "j" variable for?
You are only using "i" variable in the code...
May be try this?
Took less than 1 sec on my machine. i5, 2.5GHz, 16Gb RAM.Please Login or Register to view this content.
@CK I assume he wants to add 1 million random numbers together to store in the 1 million array items?
@tim not really no, you could try doing this for 1,000 i and j loops.... time it, and then multiply that time by 1,000,000.. that may give you a rough estimate
EDIT! I corrected the post, I said multiply by 1,000 i meant 1,000,000
Last edited by Arkadi; 01-20-2017 at 03:03 PM.
Thanks.
i will go to bed, it will calculate
tim, I don't see it really saving any time, but if your second array dimension is only 1 to 1 then you don't really need to make it a 2d array? Seems to me you could just use:
Please Login or Register to view this content.
You may also want to actually initialize the random number function:
without randomize, the "random" numbers will be the same if you run the code twicePlease Login or Register to view this content.
I do not think it will save a lot of memory.
besides, there are ussually two dimentions for working with range.
Ah, got it. I missed the part about Gaussian distribution.I assume he wants to add 1 million random numbers together to store in the 1 million array items?
Yeah, it's going to take a long time no matter how you code this one. And unfortunately, VBA can't use multi-threading to my knowledge.
1,000,000 iteration for each array element. To populate 1,000,000 array element takes about 0.73 seconds.
So... 730,000 seconds to calculate in best circumstance... 202 hours and 47 min.
Is this the goal of this code/part of the project? This is way out of my area of expertise, but I wonder if there is a better, faster algorithm for generating such random numbers.if one sums some Rnds, he will have a Gaussian distribution generator.
A quick internet search found this at Wikipedia for the Box-Muller transform: https://en.wikipedia.org/wiki/Box%E2...ller_transform
and this one: http://www.design.caltech.edu/erik/Misc/Gaussian.html
This algorithm seemed simple enough, so I tried it:
A1=RAND()
B1=RAND()
C1=SQRT(-2*LN(A1))
D1=2*PI()*B1
E1=C1*COS(D1)
F1=C1*SIN(D1)
copied down to the bottom (row 1048576). This results in two sets of random Gaussian numbers (mean~0 stdev~1). After building the spreadsheet, it calculates in about 1 second (i3 3.2 GHz). I also noted from the Box-Muller Wikipedia page that Box-Muller is considered a "slower" algorithm. Wikipedia mentions the Ziggurat algorithm that is supposedly even faster.
That is probably not the final solution to your problem. I would suggest that, if computation time is a real concern, that you do some research into other random number generation algorithms to find a faster algorithm than this "brute force" algorithm you are currently using.
Originally Posted by shg
column A just Rnd, B with Randomize
there is no difference
file is too big for the forum
code:
Please Login or Register to view this content.
MrShorty, thanks
I know about it
i used this (not satisfied):
As noted, this is far from my area of expertise, so I cannot comment in more detail. I was hoping that I had found some ideas for researching faster algorithms, but it appears that you have already researched these algorithms and found them unsuitable.
I don't see any way to speed up this brute force algorithm, so if it is the only algorithm that will work for you, it may be necessary to wait it out.
thank all of you!
1000000 was a greed, i will try 1000
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks