Re: Generating Random Values with Do[]
- To: mathgroup at smc.vnet.net
- Subject: [mg23300] Re: [mg23270] Generating Random Values with Do[]
- From: BobHanlon at aol.com
- Date: Sun, 30 Apr 2000 21:13:50 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Needs["Statistics`NormalDistribution`"]
dist1 = NormalDistribution[0, 1];
dist2 = NormalDistribution[0, 1];
To reduce the memory requirements, break 10^6 trials into 100 sets of 10000
trials.
nbrTrialsPerSet = 10000; nbrSets = 10^6/nbrTrialsPerSet; nbrRepeats = 3;
Table[Plus @@ (Table[
Count[RandomArray[dist1, nbrTrialsPerSet] -
RandomArray[dist2, nbrTrialsPerSet],
_?NonNegative], {nbrSets}]), {nbrRepeats}] // Timing
{149.26666666666665*Second, {500132, 499562, 499942}}
In a message dated 4/29/2000 10:38:49 PM, com3 at ix.netcom*NOSPAM*.com writes:
>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.
>
Bob
BobHanlon at aol.com