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

V

Verbal Kint

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!
 
M

mark_bluemel

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?
 
V

Verbal Kint

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

mark_bluemel

:) 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?
 
V

Verbal Kint

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? ;)
 
M

mark_bluemel

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

Army1987

Verbal Kint said:
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.
 
C

Clever Monkey

If you are replying to my posting, it would be helpful and polite to
quote at least the relevant parts of 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.
 
M

mark_bluemel

Should read "... you can simply multiply them ..."
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.
 
M

Mark McIntyre

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

He did:
--
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
 
K

Keith Thompson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top