By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,485 Members | 1,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,485 IT Pros & Developers. It's quick & easy.

change standard deviation of normal or Gaussian distribution (faq 13.20)

P: n/a
DEAR ALL,

I just have a very short question. In the FAQ list question 13.20 the
following text is mentioned:
"These methods all generate numbers with mean 0 and standard deviation
1. (To adjust to some other distribution, multiply by the standard
deviation and add the mean.)"

Could you please let me know, which number I have to multiply with the
standard deviation?

Thanks a lot!

Jun 29 '07 #1
Share this Question
Share on Google+
10 Replies


P: n/a
On 29 Jun, 09:21, Verbal Kint <TENSOAP...@gmail.comwrote:
DEAR ALL,

I just have a very short question. In the FAQ list question 13.20 the
following text is mentioned:
"These methods all generate numbers with mean 0 and standard deviation
1. (To adjust to some other distribution, multiply by the standard
deviation and add the mean.)"

Could you please let me know, which number I have to multiply with the
standard deviation?
I'm sorely tempted to say "42" here... But ...

The numbers generated by these methods have a specific distribution -
right?

To change that distribution, you can simply them (the numbers the
methods generate) by the required standard deviation, and add the
required mean - can't you?

Jun 29 '07 #2

P: n/a
:) I understand what you mean. Maybe I didnt express myself clear
enough. I wanted to use to following method as mentioned in FAQ:

double gaussrand()
{
static double V1, V2, S;
static int phase = 0;
double X;

if(phase == 0) {
do {
double U1 = (double)rand() / RAND_MAX;
double U2 = (double)rand() / RAND_MAX;

V1 = 2 * U1 - 1;
V2 = 2 * U2 - 1;
S = V1 * V1 + V2 * V2;
} while(S >= 1 || S == 0);

X = V1 * sqrt(-2 * log(S) / S);
} else
X = V2 * sqrt(-2 * log(S) / S);

phase = 1 - phase;

return X;
}

Now I wonder, whether I can multiply the standard deviation of e.g.
0.5 with X or with which variable (v1, v2, etc.) I need to multiply
it?
Thanks a lot.

Jun 29 '07 #3

P: n/a
On 29 Jun, 10:20, Verbal Kint <TENSOAP...@gmail.comwrote:
:) I understand what you mean. Maybe I didnt express myself clear
enough. I wanted to use to following method as mentioned in FAQ:
If you are replying to my posting, it would be helpful and polite to
quote at least the relevant parts of it.
>
double gaussrand()
{
....
return X;

}

Now I wonder, whether I can multiply the standard deviation of e.g.
0.5 with X or with which variable (v1, v2, etc.) I need to multiply
it?
I said before :-
"The numbers generated by these methods have a specific distribution -
right?

To change that distribution, you can simply them (the numbers the
methods generate) by the required standard deviation, and add the
required mean - can't you?"

What about that didn't you understand?

Let's try another approach. The FAQ said
"These methods all generate numbers with mean 0 and standard deviation
1. (To adjust to some other distribution, multiply by the standard
deviation and add the mean.)"

This instruction must apply no matter which method you used to
generate your random number, so it must not relate in any way to the
internal implementation of that random number generator - right?

So the only thing to which we can apply the instructions "multiply by
the standard deviation and add the mean" is the output of the random
number generator. Is that any clearer?

Jun 29 '07 #4

P: n/a
So the only thing to which we can apply the instructions "multiply by
the standard deviation and add the mean" is the output of the random
number generator.
Why didn't you say that right from the beginning? ;)

Jun 29 '07 #5

P: n/a
On 29 Jun, 10:53, Verbal Kint <TENSOAP...@gmail.comwrote:
So the only thing to which we can apply the instructions "multiply by
the standard deviation and add the mean" is the output of the random
number generator.

Why didn't you say that right from the beginning? ;)
Why don't you consider being polite to people who have bothered to try
to help you? Don't hope for anymore help from me.

Jun 29 '07 #6

P: n/a

"Verbal Kint" <TE********@gmail.comha scritto nel messaggio news:11**********************@n60g2000hse.googlegr oups.com...
DEAR ALL,

I just have a very short question. In the FAQ list question 13.20 the
following text is mentioned:
"These methods all generate numbers with mean 0 and standard deviation
1. (To adjust to some other distribution, multiply by the standard
deviation and add the mean.)"

Could you please let me know, which number I have to multiply with the
standard deviation?
This is not really a question about C, but

extern double std_gauss(void);
#define gauss(mean, stdev) ((mean) + (stdev) * std_gauss())
double (gauss)(double mean, double stdev)
{
return gauss(mean, stdev);
}

HTH.
Jun 29 '07 #7

P: n/a
ma**********@pobox.com wrote:
On 29 Jun, 10:20, Verbal Kint <TENSOAP...@gmail.comwrote:
>:) I understand what you mean. Maybe I didnt express myself clear
enough. I wanted to use to following method as mentioned in FAQ:

If you are replying to my posting, it would be helpful and polite to
quote at least the relevant parts of it.
>double gaussrand()
{
...
> return X;

}

Now I wonder, whether I can multiply the standard deviation of e.g.
0.5 with X or with which variable (v1, v2, etc.) I need to multiply
it?

I said before :-
"The numbers generated by these methods have a specific distribution -
right?

To change that distribution, you can simply them (the numbers the
methods generate) by the required standard deviation, and add the
required mean - can't you?"

What about that didn't you understand?
Well, to be fair, I didn't understand what you meant by that paragraph.
You seem to have a missing verb in there somewhere. I tried inserting
the word "multiply" in a few places, but was not completely satisfied
with the results.
Jun 29 '07 #8

P: n/a
On 29 Jun, 15:22, Clever Monkey <spamt...@clevermonkey.org.INVALID>
wrote:
mark_blue...@pobox.com wrote:
On 29 Jun, 10:20, Verbal Kint <TENSOAP...@gmail.comwrote:
:) I understand what you mean. Maybe I didnt express myself clear
enough. I wanted to use to following method as mentioned in FAQ:
If you are replying to my posting, it would be helpful and polite to
quote at least the relevant parts of it.
double gaussrand()
{
...
return X;
}
Now I wonder, whether I can multiply the standard deviation of e.g.
0.5 with X or with which variable (v1, v2, etc.) I need to multiply
it?
I said before :-
"The numbers generated by these methods have a specific distribution -
right?
To change that distribution, you can simply them (the numbers the
Should read "... you can simply multiply them ..."
methods generate) by the required standard deviation, and add the
required mean - can't you?"
What about that didn't you understand?

Well, to be fair, I didn't understand what you meant by that paragraph.
You seem to have a missing verb in there somewhere. I tried inserting
the word "multiply" in a few places, but was not completely satisfied
with the results.
Good point, inadequate proof-reading acknowledged - but, in my
defense, I'd point out that the "multiply by std dev and add mean"
thing was already well established.

Jun 29 '07 #9

P: n/a
On Fri, 29 Jun 2007 09:53:44 -0000, in comp.lang.c , Verbal Kint
<TE********@gmail.comwrote:
>So the only thing to which we can apply the instructions "multiply by
the standard deviation and add the mean" is the output of the random
number generator.

Why didn't you say that right from the beginning? ;)
He did:
>>To change that distribution, you can simply them (the numbers the
methods generate) by the required standard deviation, and add the
required mean - can't you?
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jun 29 '07 #10

P: n/a
ma**********@pobox.com writes:
On 29 Jun, 10:53, Verbal Kint <TENSOAP...@gmail.comwrote:
So the only thing to which we can apply the instructions "multiply by
the standard deviation and add the mean" is the output of the random
number generator.

Why didn't you say that right from the beginning? ;)

Why don't you consider being polite to people who have bothered to try
to help you? Don't hope for anymore help from me.
Note the smiley. I thought (and still think) that "Verbal Kint" was
making a joke at his own expense.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 30 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.