Jump to content

normal distribution / standard deviation stuff?


fivestringsurf

Recommended Posts

Hi all,

 

I'm not sure if there is a super lean way to randomly generate standard deviations based on normal distribution (bell curve), but if there is ...I'm all ears, uh eyes that is:). 

 

Ok- normal distribution; you know; the law that states: there is a %68.3 percent chance of a number (standard deviation) landing in between and including -1 to 1... a %27.2 chance for greater than 1 less than and including 2 or less than -1 greater than and including -2...and so on. 

 

When it comes to math and coding I usually get the job done but in my own way.  I have found a solution but it involves writing one large array [1000 entries long] on the fly each time and consists of randomly generated values that fit the normal distribution model.  When I run tests, my results confirm it does work and as expected- the  larger the data pool  the closer the results get to a precise normal distribution (law of averages at work! flip a coin a million times and you get closer to 50/50)

 

Can't i use some nifty formula to randomly produce numbers through out the normal distribution curve?

As it stands now I am running several loops to build the master list of normally distributed numbers before I even use them....seems like some overhead here???

 

Please advise, thank you.

Link to comment
Share on other sites

If you generate few random numbers (using rand() which produces a flat distribution) and take the average and then repeat that a few times the result will be a set of more or less normally distributed values.  The greater the number of of rands() you average the closer the distribution will be to normal.

 

You can try it with dice - throw one die a few times and you'll get a flat distribution, throw 5 or 6 each time and the result will be pretty much normal.

Link to comment
Share on other sites

  • 2 weeks later...

thanks for the reply...the notification of your post got spammed and i just found it by chance....  Interesting approach.  Similar to mine from the start but i tried your idea out just for haha's...  The weird part is I don't get the usual "normal distribution" when i run large tests  %68, %27, etc... I get results near  %48, %27, %17, %7.  ?  strange.  any thoughts?  here's my code:

<?php
$rand = mt_rand(0,100);
$ave =0;
$pickAndSave = array();
for ($n=0; $n<10000; $n++){
$tot = 0;
for ($i=0; $i<2; $i++){
	$rand = mt_rand(-4,4);
	$tot += $rand;
}

$ave = $tot/2;
$pickAndSave[] = $ave;
}

//will hold tally
$sd1 = 0;
$sd2 = 0;
$sd3 = 0;
$sd4 = 0;
//tally results
foreach($pickAndSave as $val){
if ($val < -3 || $val > 3){
	$sd4++;
}elseif($val < -2 || $val > 2){
	$sd3++;
}elseif($val < -1|| $val > 1){
	$sd2++;
}elseif($val <= 0 || $val >= 0){
	$sd1++;
}else{
	echo 'error: number out of bounds!';
}
}
$tot = $sd4 + $sd3 + $sd2 +$sd1;
//print results
echo '<pre>';
echo "Report:";
echo "\n $sd1 ". $sd1/$tot *100;
echo "\n $sd2 ". $sd2/$tot *100;
echo "\n $sd3 ". $sd3/$tot *100;
echo "\n $sd4 ". $sd4/$tot *100;
?>

 

Report:
4817 48.17
2688 26.88
1744 17.44
751 7.51

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.