RE:
- To: mathgroup at smc.vnet.net
- Subject: [mg23343] RE:[mg23270]
- From: "Higinio Ramos Calle" <higra at gugu.usal.es>
- Date: Thu, 4 May 2000 02:59:11 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
----- Original Message ----- From: <com3 at ix.netcom*NOSPAM*.com> To: mathgroup at smc.vnet.net Subject: [mg23343] [mg23270] Generating Random Values with Do[] > Hi, > > I'm just at the beginning level of Mathematica programming and I need > to simulate a probabilistic process. I've constructed the code below > which (I believe) works fairly well. The intent is to compute the > number of times a randomly sampled value from distribution #1 will > equal or exceed a random sample from distribution #2 when a million > samples from each are compared. This is then repeated 3 times . I've > used ver. 3.0 for this. I have 3 questions though. > > 1) How can I enhance this code such that I can easily change the > number of repeats, say from 3 to 10 without copying and pasting the > code ? Can this be done via an outer Do command ? > > 2) Because a million samples from the two distributions are being > produced and compared, execution time is becoming an issue. Is there a > way I can speed up this code ? > > 3) I understand that the random number generation seed is determined > from the system date. Could I be getting sub-quality random number > generation in my code ? In other words, do I need to worry about > "re-seeding" each time I call Random ? > > To get instant execution of the code, you can change the 10^6 to 10^2. > > Thanks in advance for any help suitable for the beginner. > > Steve > > > Needs["Statistics`NormalDistribution`"] > Remove["`*"] > counter={}; > count=0; > dist1=NormalDistribution[0,1]; > dist2=NormalDistribution[0,1]; > Do[If[Random[dist1] \[GreaterEqual] Random[dist2], count = count + 1, > count = count], {10^6}] > counter=Append[counter,count] > count=0 > Do[If[Random[dist1] \[GreaterEqual] Random[dist2], count = count + 1, > count = count], {10^6}] > counter=Append[counter,count] > count=0 > Do[If[Random[dist1] \[GreaterEqual] Random[dist2], count = count + 1, > count = count], {10^6}] > counter=Append[counter,count] Here is a posible response Needs["Statistics`NormalDistribution`"] Remove["`*"] counter={}; timesYouDo[n_]:=Module[{count,dist1,dist2}, dist1=NormalDistribution[0,1]; dist2=NormalDistribution[0,1]; Do[count=0; Do[If[Random[dist1] \[GreaterEqual] Random[dist2], count = count + 1, count = count], {10^2}]; counter=Append[counter,count],{n}];counter] where in n you put the times you want to repeat the task. Higinio Ramos Dpto. Matematica Aplicada U. de Salamanca