Aha, now I see 
Then what you're looking for is probably a random number generator with a "normal distribution" (you can check this out on the web, basically means that numbers will tend to be closer to a given number).
(Dont know all these words in english but I'll try to explain :P)
A normal distribution (also called gauss distribution) is written as N(0,1), where 0 is the mean ("avarge") outcome and 1 is the variance (how much the numbers can differ from the avarage). In your case, with your given example, you'll want N(17,20).
I found a piece of code on php.net which does this:
PHP Code:
<?php
function gauss() { // N(0,1) // returns random number with normal distribution: // mean=0 // std dev=1 // auxilary vars $x=random_0_1(); $y=random_0_1(); // two independent variables with normal distribution N(0,1) $u=sqrt(-2*log($x))*cos(2*pi()*$y); $v=sqrt(-2*log($x))*sin(2*pi()*$y); // i will return only one, couse only one needed return $u; }
function gauss_ms($m=0.0,$s=1.0) { // N(m,s) // returns random number with normal distribution: // mean=m // std dev=s return gauss()*$s+$m; }
function random_0_1() { // auxiliary function // returns random number with flat distribution from 0 to 1 return (float)rand()/(float)getrandmax(); }
?>
EDIT: The code I found is a few years old, it is better to use the new functions mt_rand() and mt_getrandmax() instead of rand() and getrandmax().
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
Last edited by lizciz; 01-07-2010 at 07:20 AM..
|