May 23rd, 2009, 4:09 pm
Hi,I plan to do 10,000 runs and then calculate average as expectation. For each run, I have 10000 steps, therefore I need to generate 10,000*10000 normally distributed numbers. I am using MATLAB for coding.I heard from someone (a class that I attended) that:In Monte Carlo code, do not include RANDN in a loop, because same seed gives same number. Generate all random numbers initially by generating RANDN(A) for a large enough matrix ATextsdfd However, I tried following MATLAB code:-----a=zeros(5,4);for i=1:5 for j=1:4 a(i,j)=randn(1,1); endenda-----I saw the generated value of a are always different, conflicting with above statement.So, my question are:(1) Is above statement correct?(2) when you do MC simulation, how do you treat the situation of generating 10,000*10000 random numbers? create them at one time at beginning or do in loop structures?(3) Can I directly use rand() function in Matlab to generate uniformly distributed numbers? Is the result from rand() fully-period? Do I need to use some method, such as linear congruential, to create by myself?(4) Do you use some method, such as Box-Mueller, to generate normally distributed numbers?Thanks a lot for your answers.
Last edited by
huayen on May 22nd, 2009, 10:00 pm, edited 1 time in total.