448,485 Members | 1,061 Online
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
10 Replies

 P: n/a On 29 Jun, 09:21, Verbal Kint

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

 P: n/a "Verbal Kint"

 P: n/a ma**********@pobox.com wrote: On 29 Jun, 10:20, Verbal Kint :) I understand what you mean. Maybe I didnt express myself clearenough. 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 multiplyit? 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 wrote: mark_blue...@pobox.com wrote: On 29 Jun, 10:20, Verbal Kint

 P: n/a On Fri, 29 Jun 2007 09:53:44 -0000, in comp.lang.c , Verbal Kint So the only thing to which we can apply the instructions "multiply bythe standard deviation and add the mean" is the output of the randomnumber generator. Why didn't you say that right from the beginning? ;) He did: >>To change that distribution, you can simply them (the numbers themethods generate) by the required standard deviation, and add therequired 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 San Diego Supercomputer Center <* "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.