Posts: 3,368
Threads: 195
Joined: Jan 2003
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
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 1,439
Threads: 15
Joined: Apr 2003
You might be better off with the
source.
Posts: 3,368
Threads: 195
Joined: Jan 2003
Hey, thanks, but that's actually not it, er.. it doesn't give a random number.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 1,439
Threads: 15
Joined: Apr 2003
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
)...
Posts: 3,368
Threads: 195
Joined: Jan 2003
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
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 3,616
Threads: 287
Joined: Jan 2003
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.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 1,407
Threads: 117
Joined: Dec 2002
Use the RND to index in an acumulated distribution table... Or as an entry to a function returning the acumulated distribution.
Antoni
Posts: 3,368
Threads: 195
Joined: Jan 2003
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.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.