Re: İlgi: [PHP] a for loop and probability random all i need is make them to reverse
2008/11/22 Tontonq Tontonq <[EMAIL PROTECTED]>: > sorry i think i did tell u wrong about it problem is not showing name > of it as exaclty i just wanted give a point to it thats not real > problem real problem is i want it be more unpossible when i give the > class's add function's higher value In that case I would go for an algorithm using some kind of gaussian distribution, like the Marsaglia polar method [1]. I once wrote something similar to what (I think) you are asking for ... 1) { $u1 = 1/(rand(1, $likelihood)*$likelihood); $u2 = 1/(rand(1, $likelihood)*$likelihood); $v = $u1*$u1 + $u2*$u2; } $p = $u1*sqrt((-2)*(log($v)/$v)); return ($p < 0.85) ? 1 : (int)$p; } ?> The best return of this function would be 1. Now if you call the function with a high $likelihood (say 1000 and more) it gets less likely have 1 returned ( gaussian ). If you want to decrease the chance of getting values close to 1 then you will have to increase $likelihood inside the function or something. [1] http://en.wikipedia.org/wiki/Marsaglia_polar_method -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
İlgi: [PHP] a for loop and probability random all i need is make them to reverse
sorry i think i did tell u wrong about it problem is not showing name of it as exaclty i just wanted give a point to it thats not real problem real problem is i want it be more unpossible when i give the class's add function's higher value 2008/11/22, Yeti <[EMAIL PROTECTED]>: > That should output the full line now > > $prExample = new probabilityRandom; > > > function arasi($a,$b,$data) > { > $x = explode($a,$data); > $z = explode($b,$x[1]); > $oh = $z[0]; > if($x && $z) { return $oh; } else { return false; } > } > > > $x="jZRBb9swDIXvA/YfdFyxHJK0GHadvc7tYUAQb+iZiWlHKGUFkpy1+/WTE7uzFcr1MSbz+NmPj1s4Om3E55X4tBKyFl/Wi+VyefPxQ0Zwwv/PV+vF3fl5epDO//5mlP/bBhoqjK4HfYv1Xdv2oyESGwKH0dbbVdu40U76p7oUuW6oK3299ZWEoPD/fkGGLtE1ipTQM5r3IQs7C3DYFsI9SVtoNcTLDBxAMWw5wesU1QOSQjeDKGy8MD35BtMilXDSxg6RfmmHSu5FfkTgPH0Ac9QjtwK0DJraEbo536vvjfJVBvY4xHts7U/0H4bsXEqNtnY3rId8idaz2IK+zkxZP4ut9EwpPHswq4DoZgh4T/JFGpE7KEvOWCBQUBd41fLGudVV4/XnZeTSPD8pAb+SRUE4eoH8AKZgyH9KAxWK71BV7Gay2FxqoshMdgJcAlONaTdGonXiUR1h7xjqrn7O+t6APbzPHstWhJtPWKapEDufoJ5n2V8dQmuxEL+Pfrf9bcr3RhNNAk0kKsIUyxU79OK6pPYMDokD4HtChbUDmoMcCVkEl41aaqSyfoO3eofXSql5tS3LuNp9e4NYT6e0F99AzXH26kE5Is+EqNeP7VI/ILI84YTrve8HZKRPOPEGYb0bQI13STd2OORaPOJir83alrs2av50kyyRSerMu9Z1zz5sCf7Vb7s7MY87SPFZzEUaqcbsjSnydo81J9Iek43FfSwccTMmyrj7Dw=="; > $x = gzinflate(base64_decode($x)); > $xx=explode(" > ",$x); > $xcx=array(); > > foreach($xx as $c => $y) > { > $yy = arasi(" in ",")",$y); > $yy = str_replace(",","",$yy); > $xcx[]=$yy; > #echo $yy.""; > $itemisim = explode("(",$y); > $itemisim=$itemisim[0]; > $xcx[isim][]=$itemisim; > } > for($i=0;$i<=count($xcx)-1;$i++) > { > $prExample->add( $xx[$i], $xcx[$i] ); // <-- changed to $xx[i] > } > print $prExample->get(); > > class probabilityRandom { > #private vars > var > $data = array(), > $universe = 0; > #add an item to the list and defines its probability of beeing chosen > function add( $data, $probability ){ > $this->data[ $x = sizeof( $this->data ) ] = new stdClass; > $this->data[ $x ]->value = $data; > $this->universe += $this->data[ $x ]->probability = abs( $probability ); > } > #remove an item from the list > function remove( $index ){ > if( $index > -1 && $index < sizeof( $this->data ) ) { > $item = array_splice( $this->data, $index, 1 ); > $this->universe -= $item->probability; > } > } > #clears the class > function clear(){ > $this->universe = sizeof( $this->data = array() ); > } > #return a randomized item from the list > function get(){ > if( !$this->universe ) > return null; > $x = round( mt_rand( 0, $this->universe ) ); > $max = $i = 0; > do > $max += $this->data[ $i++ ]->probability; > while( $x > $max ); > return $this->data[ $i-1 ]->value; > } > } > ?> > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] a for loop and probability random all i need is make them to reverse
That should output the full line now $y) { $yy = arasi(" in ",")",$y); $yy = str_replace(",","",$yy); $xcx[]=$yy; #echo $yy.""; $itemisim = explode("(",$y); $itemisim=$itemisim[0]; $xcx[isim][]=$itemisim; } for($i=0;$i<=count($xcx)-1;$i++) { $prExample->add( $xx[$i], $xcx[$i] ); // <-- changed to $xx[i] } print $prExample->get(); class probabilityRandom { #private vars var $data = array(), $universe = 0; #add an item to the list and defines its probability of beeing chosen function add( $data, $probability ){ $this->data[ $x = sizeof( $this->data ) ] = new stdClass; $this->data[ $x ]->value = $data; $this->universe += $this->data[ $x ]->probability = abs( $probability ); } #remove an item from the list function remove( $index ){ if( $index > -1 && $index < sizeof( $this->data ) ) { $item = array_splice( $this->data, $index, 1 ); $this->universe -= $item->probability; } } #clears the class function clear(){ $this->universe = sizeof( $this->data = array() ); } #return a randomized item from the list function get(){ if( !$this->universe ) return null; $x = round( mt_rand( 0, $this->universe ) ); $max = $i = 0; do $max += $this->data[ $i++ ]->probability; while( $x > $max ); return $this->data[ $i-1 ]->value; } } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] a for loop and probability random all i need is make them to reverse
i want it returns *Raptor +1 (1 in 62,000) * but it returns me nearly everytime how can i make them reverse help me please index.php > $y) { $yy = arasi(" in ",")",$y); $yy = str_replace(",","",$yy); $xcx[]=$yy; #echo $yy.""; $itemisim = explode("(",$y); $itemisim=$itemisim[0]; $xcx[isim][]=$itemisim; } for($i=0;$i<=count($xcx)-1;$i++) { $prExample->add( $xcx[isim][$i], $xcx[$i] ); } print $prExample->get(); ?> lib.probabilityRandom.php > http://www.joninhas.ath.cx:666 - CLASS --- My user account at phpclasses.org http://www.phpclasses.org/browse.html/author/84147.html Get the latest version of this class at: http://www.phpclasses.org/browse.html/package/1940.html - VERSION & HISTORY --- v1.0 2004-10-31 - Class creation - **/ class probabilityRandom { #private vars var $data = array(), $universe = 0; #add an item to the list and defines its probability of beeing chosen function add( $data, $probability ){ $this->data[ $x = sizeof( $this->data ) ] = new stdClass; $this->data[ $x ]->value = $data; $this->universe += $this->data[ $x ]->probability = abs( $probability ); } #remove an item from the list function remove( $index ){ if( $index > -1 && $index < sizeof( $this->data ) ) { $item = array_splice( $this->data, $index, 1 ); $this->universe -= $item->probability; } } #clears the class function clear(){ $this->universe = sizeof( $this->data = array() ); } #return a randomized item from the list function get(){ if( !$this->universe ) return null; $x = round( mt_rand( 0, $this->universe ) ); $max = $i = 0; do $max += $this->data[ $i++ ]->probability; while( $x > $max ); return $this->data[ $i-1 ]->value; } } ?>