# Normal Distribution Histogram

• 02-06-2013
Michael Rupert
Normal Distribution Histogram
Hey guys, I'm stuck on the beginning of this assignment. I've been googling it for hours and re watching the lecture, but I can't figure it out.

PROBLEM: Write a function that generates 1000 normally distibuted (Gaussian Probabliity Distribution) random numbers. Range should be between -3 and +3. Numbers should be double floating point.

There's more to it than that, but I've got it from there.

Thanks!
• 02-06-2013
std10093
Michael, welcome to the forum :D

First of all, in parallel some other people asked about Random numbers ∈[min, max].
• 02-06-2013
anduril462
@std10093
That will only give him numbers that are more or less uniformly distributed. He needs a normal (aka Gaussian) distribution.

@Michael Rupert
You didn't specify a standard deviation for your distribution, so I assume it will be 1.
Check this out: Normal distribution - Wikipedia, the free encyclopedia. The second method listed, based on the central limit theorem, is pretty easy to implement. Note that it gives you values from -6 to +6. You can find various ways to scale that to your needs of [-3, 3]. Note, the more numbers you sum up, the more accurate your distribution will be, so long as you scale it down correctly, to fit your +/-3 range.

Note, I'm not a math expert, so I can't really speak to how scaling that method up/down will affect the overall accuracy/precision of your results, nor how to adapt that to a standard deviation other than 1.
• 02-06-2013
Michael Rupert
Quote:

Originally Posted by anduril462
@Michael Rupert
You didn't specify a standard deviation for your distribution, so I assume it will be 1.
Check this out: Normal distribution - Wikipedia, the free encyclopedia. The second method listed, based on the central limit theorem, is pretty easy to implement. Note that it gives you values from -6 to +6. You can find various ways to scale that to your needs of [-3, 3]. Note, the more numbers you sum up, the more accurate your distribution will be, so long as you scale it down correctly, to fit your +/-3 range.

Note, I'm not a math expert, so I can't really speak to how scaling that method up/down will affect the overall accuracy/precision of your results, nor how to adapt that to a standard deviation other than 1.

As a new C user, I honestly have no idea how to even start to implement that, could anyone give me a hand?
• 02-06-2013
anduril462
Just how new are you? Honestly, if you can't even start to implement that, then the level required for this assignment does not seem to jive with your abilities. From a basic programming standpoint: Can you generate 12 random numbers? Can you subtract one number from another? From a general problem solving standpoint: can you implement that method by hand? If not, you stand no chance of writing a program to do so.

Perhaps you could provide links to the actual homework assignment, and the video lecture(s). Can't say I'll watch the whole thing, but it might give an idea of what level the teacher expects you to be at. Maybe there are some clues in the assignment you're missing.
• 02-07-2013
Michael Rupert
PROBLEM: Write a function that generates 1000 normally distributed (Gaussian Probabliity Distribution) random numbers. Range should be between -3 and +3. Numbers should be double floating point. And different random numbers should come out every time it runs. Use the putpixel function (graphics.h), or the bar function (graphics.h) plot a histogram of the numbers you generated. Try to have somewhere between 20 and 40 bins. You will know you have the correct answer when the histogram has a somewhat bell curve shape.
• 02-07-2013
anduril462
There are still so many questions.

• Is that the complete problem description, copied verbatim?
• What is your background in C? What about programming in general? Matlab?
• You must understand the problem before you can program a solution.
• Have you ever been taught what a normal/Gaussian distribution is? What is your background in statistics?
• Do you know what a histogram is? Can you create a histogram on paper with, say, 10 bins, and fill it with a uniform distribution of 50 random numbers? Google "online random number generator" to get some random data for your paper histogram.
• Can you show us any attempt to solve this problem yourself? Have you tried writing any code at all? Note, we don't hand out free homework here, we help you learn. That requires some show of effort, of good faith, on your part.
• 02-07-2013