Qbasicnews.com
random value given a standard normal distribution and mean? - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html)
+--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html)
+--- Thread: random value given a standard normal distribution and mean? (/thread-8987.html)



random value given a standard normal distribution and mean? - Agamemnus - 03-07-2006

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/FindProbability.class


random value given a standard normal distribution and mean? - DrV - 03-07-2006

You might be better off with the source.


random value given a standard normal distribution and mean? - Agamemnus - 03-07-2006

Hey, thanks, but that's actually not it, er.. it doesn't give a random number.


random value given a standard normal distribution and mean? - DrV - 03-07-2006

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 )...


random value given a standard normal distribution and mean? - Agamemnus - 03-08-2006

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



random value given a standard normal distribution and mean? - Zack - 03-08-2006

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.


random value given a standard normal distribution and mean? - Antoni Gual - 03-08-2006

Use the RND to index in an acumulated distribution table... Or as an entry to a function returning the acumulated distribution.


random value given a standard normal distribution and mean? - Agamemnus - 03-09-2006

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.