Qbasicnews.com

Full Version: random value given a standard normal distribution and mean?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to do a simulation of projected sales. I can't get my head around how to create a random number that follows a certain probability distribution, specifically the standard normal distribution.

Given a mean of sample_mean and a standard deviation of sample_sd, how can I get a random number off of them? Anyone?

Here is a website that does this, but I can't convert the .class files into meaningful code...

http://www-stat.stanford.edu/~naras/jsm/...lity.class
You might be better off with the source.
Hey, thanks, but that's actually not it, er.. it doesn't give a random number.
Hmm, you're right... I didn't actually read it. :oops: No idea then, sorry... I think I've read about such things before, but the importance of having "good" random numbers escaped me at the time (and still does Smile )...
I figured out a nice way to translate the sample into a distribution from which you can draw random vars from.

Code:
for j = 1 to test_var_amount
test_var = 0
for i = 1 to sample_amount
test_var = test_var + sample_var(i)
next i
test_var = test_var / sample
next j
Why not just do this (for instance):
Code:
[pseudocode]
r=random number from 1 to 4, inclusive
if r is 1 or r is 2 then call A()
if r is 3 then call B()
if r is 4 then call C()
[/pseudocode]
That way there is a 50% chance of A() being called, and a 25% of B or C being called.
Use the RND to index in an acumulated distribution table... Or as an entry to a function returning the acumulated distribution.
Antoni Gual: Yeah, it is a good way to do it, but you need to actually create the distributions first for each value..

Zack, that's basically what Antoni is suggesting except a lot more convoluted. :wink:

But it's ok, I figured it out.