Normal Distribution

I made this JS animation to visualize the random distribution. Shouldn't I be seeing something like the red curve? What happened?

Other urls found in this thread:

jsfiddle.net/victorqribeiro/Lf77yw98/
en.wikipedia.org/wiki/Inverse_transform_sampling
jsfiddle.net/f288pxtq/
jsfiddle.net/w0oqc72d/1/
en.wikipedia.org/wiki/Bean_machine
twitter.com/NSFWRedditImage

Link to the animation

jsfiddle.net/victorqribeiro/Lf77yw98/

>100% cpu rendering some snowflakes at 320x240 at 20fps

So.. this.. is the absolute power.. of javascript

Random (uniform) distribution is literally not a normal distribution, learn elementary statistics you dense fuck.

>it's another fagot coder thinks he's an expert in everything because he can write some programming language episode

Your curve is a normal distribution, but you're dropping flakes using a uniform distribution (Math.random).

I see. Thanks a lot.

Yeah, I got that now... uniform and normal are very similar words in my language. I got confused.

Nope, not true. I don't think I'm a expert on nothing. And I also don't copy paste code. Although I watch a lot of code train episodes.

>learning statistics in your native language instead of in english
I take it you never took any statistics classes at university then.

whatever dude.

> why isn't my uniform distribution normal distributed?

That's a uniform distribution you're generating fucking retard, not a normal distribution.

>uniform and normal are very similar words in my language
That's pretty interesting. What language?

Hebrew

Slovakian

The fiddle is made a Brazilian, on Portuguese normal is normal and uniform is uniforme.

He was probably trying to learn stats from some retarded hip Javascript medium post made by some code artisan.

Also user, if you are trying to see how a normal curve can emerge from a munch of uniform random distributions check the central limit theorem.

Basically, if count the height of each pixel column on your animation, and you count equal results (that is, you calculate how many columns have 0 dots, how many have 1 dot... until you counted all the columns), and now you plot that count against the number of dots it as, you will see a little bell curve.

now you can see a normal distribution using uniform distribution. This works because the average of numbers generated in the same uniform distribution tend to be the mid point of the interval. If you take the average of only 2 numbers there isn't a big change that it will hit the mid point but if you repeat that several times and then take another average, the final average will be. If that's not intuitive you need to review basic statistics.
var n = 100 // amount of times the experiment is repeated.
var amountOfBins = 10 // amount of colunms in your normal distribution.
var bins = new Array(amountOfBins).fill(0)
for (var i = 0; i < n; i++) {
var a = Math.random()*amountOfBins
var b = Math.random()*amountOfBins
bins[((a+b)/2)|0] += 1 // "((a+b)/2)|0" is the same as Math.floor((a+b)/2).
}
console.log(bins)

Thanks

You absolute mouthbreather of a person go to university or at least try to fucking google shit before making horrible threads like this.
en.wikipedia.org/wiki/Inverse_transform_sampling
Basically you need to first transform the normal distribution into a cumulative distribution function, which you can get by integrating the function of the normal distribution. After that you inverse that new function and calculate normally distributed pseudo randoms the following way.
inverse_cumulative_normal(Math.random())
I am sure you can find already complete examples online, you didn't have to make this thread.

jsfiddle.net/f288pxtq/

No, this is the power of op.

All the mad brainiacs in this thread. For people with such a mastery of statistics, you sure are miserable.

jsfiddle.net/w0oqc72d/1/
change distr, your solution assumes "1" as distr.

it will still look shit because confettis grab each other vertically.

This is highschool-tier math. If you can't understand the difference between a uniform and normal distribution, you may very well have been dropped on the head as a child.

>some pajeettier foreign programmer proves yet again that CS is a meme degree

Damn bro, you showed him, you're truly a superior human bean. Now go call your gf.

I think I'll call yours instead, brainlet.

if you're seriously triggered over being called out on your retardation then maybe this site isn't for you.

I'm triggered? Who's having a good boy fit over someone trying to learn something new? I just feel sorry for the lack of joy in your lives :(

>t. brainlet buttmad he can't solve P vs NP

lmao dude, I'm not the guy you're replying to, but just delete this useless fucking thread and save your anonymous self the last shred of dignity you have.
Crack a book and use google.

I'm not OP. I've taken stats and probability so I know the difference between a normal/uniform distribution. It's just irritating after a while seeing how people here are dickheads for no reason, like they came out of the womb knowing everything. OP is trying to learn something new and made a mistake. Only reason to sperg out at him is if you're a joyless loser with no self esteem.

this shouldn't be the fist place someone posts when they have an issue. This is an introductory statistics issue. If every idiot came here and posted a thread with the banal shit they don't understand this place would be overrun. If he posted this on stackexchange, a place for posting these kinds of questions, his thread would get locked because it's been answered already and he should use the search function.

>If every idiot came here and posted a thread with the banal shit they don't understand this place would be overrun.

Have you forgotten where you are? I'd rather this over "arch linux/systemd sux", "check out my pedo desktop", and "itoddlers btfo". At least someone might learn something from a thread like this.

Retards like you have zero actual intelligence and can only pride yourselves on the ability to recognize patterns through rote memorization. You are bottom feeding scum and should kill your self.

there's a reason why homework threads are banned on /sci/
>that projection

You're projecting your own projecting, how ironic

I bet you don't know what a normal distribution even is.

This
OP's animation is actually pretty cool
Good job OP, and good for wanting to learn things
I was thinking too what physical procedures could generate a normal distribution
As it turns out many atomic procedures generate normal distributions but not many macro-mechanical procedures

OP, take your code, add better collision detection, add "pins" and implement a bean machine

>en.wikipedia.org/wiki/Bean_machine

Okay, you can stop projecting now.

...

It is more then just a lump shaped thing you absolute imbecile. If you really knew you would be able to say it. Go on, don't you want to show off?

You remind me of my statistics professor in college who gave me an F because he got mad at me for correcting him in class

Sounds like you got an F because you incorrectly "corrected" your professor and refused to learn what he was teaching

No, he made an actual mistake and admitted as much when I pointed it out. He was projecting, because I would have given him an F as a professor for claiming to be an expert and still making stupid mistakes.

You're projecting your own projection of projected projections.

made the change in your code so you can see it working. change the init function and add that new control variable.
let normalWidth = 4 // the higher this numbers is, the tighter the normal becomes.
function init(){
for(let i = 0; i < a_max; i++){
let average = 0
for(let m = 0; m < normalWidth; m++) { // the more
average += Math.random()*w // you add random numbers generated uniformly.
}
average = average/normalWidth // the higher the chance the average has to hit the mid point.
a.push(new Obj(average,-Math.random()*h*normalWidth));
}
animate();
}