[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 ? include( 'lib.probabilityRandom.php' ); $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=Raptor +1 (1 in 62,000) Glave +1 (1 in 12,400) Chitin Armor Pauldron +1 (1 in 1,240) Full Plate Armor Pauldron +1 (1 in 310) Potion of Soul (1 in 83) Blade Axe +1 (1 in 62,000) Bone Cleaver +1 (1 in 12,400) Chitin Armor Pads +1 (1 in 1,240) Full Plate Armor Pads +1 (1 in 310) Potion of Wisdom (1 in 83) Graham +1 (1 in 62,000) Slayer +1 (1 in 12,400) Chitin Helmet +1 (1 in 1,240) Full Plate Armor Helmet +1 (1 in 310) Water of favors (1 in 83) Totemic Spear +1 (1 in 62,000) Harpoon +1 (1 in 12,400) Chitin Gauntlets +1 (1 in 1,240) Full Plate Armor Gauntlet +1 (1 in 310) Water of grace (1 in 83) Iron Bow +1 (1 in 62,000) Iron Crossbow +1 (1 in 12,400) Chitin Boots +1 (1 in 1,240) Full Plate Armor Boots +1 (1 in 310) Pink Rice Cake (small) (1 in 83) Elixir Staff +1 (1 in 62,000) Salamander Staff +1 (1 in 12,400) Rogue Chitin Armor Pauldron +1 (1 in 1,240) Rogue Full Plate Armor Pauldron +1 (1 in 310) Pink Rice Cake (middle) (1 in 83) Shard +1 (1 in 62,000) Mirage Dagger +1 (1 in 12,400) Rogue Chitin Armor Pads +1 (1 in 1,240) Rogue Full Plate Armor Pads +1 (1 in 310) Pink Rice Cake (large) (1 in 83) Priest Impact +1 (1 in 62,000) Priest Bone crasher +1 (1 in 12,400) Rogue Chitin Helmet +1 (1 in 1,240) Rogue Full Plate Armor Helmet +1 (1 in 310) Gold bar (1 in 620,000) Blessed Upgrade Scroll (1 in 12,400) Rogue Chitin Gauntlets +1 (1 in 1,240) Rogue Full Plate Armor Gauntlet +1 (1 in 310) Upgrade Scroll (1 in 83) Silver bar (1 in 62,000) Blessed Elemental Scroll (1 in 12,400) Rogue Chitin Boots +1 (1 in 1,240) Rogue Full Plate Armor Boots +1 (1 in 310) Crimson Robe +1 (1 in 1,240) Crystal Robe +1 (1 in 310) Green Rice Cake (small) (1 in 83) Crimson Pants +1 (1 in 1,240) Crystal Pants +1 (1 in 310) Green Rice Cake (middle) (1 in 83) Crimson Helmet +1 (1 in 1,240) Crystal Helmet +1 (1 in 310) Green Rice Cake (large) (1 in 83) Crimson Gloves +1 (1 in 1,240) Crystal Gloves +1 (1 in 310) Glutinous Rice Cake (1 in 83) Crimson Boots +1 (1 in 1,240) Crystal Boots +1 (1 in 310) Stone of life (1 in 83) Priest Chitin Armor Pauldron +1 (1 in 1,240) Priest Full Plate Armor Pauldron +1 (1 in 310) Bezoar (1 in 83) Priest Chitin Armor Pads +1 (1 in 1,240) Priest Full Plate Armor Pads +1 (1 in 310) Priest Chitin Helmet +1 (1 in 1,240) Priest Full Plate Armor Helmet +1 (1 in 310) Priest Chitin Gauntlets +1 (1 in 1,240) Priest Full Plate Armor Gauntlet +1 (1 in 310) Priest Chitin Boots +1 (1 in 1,240) Priest Full Plate Armor Boots +1 (1 in 310); $xx=explode( ,$x); $xcx=array(); foreach($xx as $c = $y) { $yy = arasi( in ,),$y); $yy = str_replace(,,,$yy); $xcx[]=$yy; #echo $yy.br; $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 ?php /** - DEVELOPER --- Jonas Raoni Soares Silva Applications Developer [EMAIL PROTECTED] 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; } } ?
Re: [PHP] a for loop and probability random all i need is make them to reverse
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.br; $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
İ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.br; $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: İ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 ... ?php function marsaglia($likelihood) { // adapted polar-method by marsaglia if (!is_numeric($likelihood) || ($likelihood == 0)) $likelihood = 100; elseif ($likelihood = 1) return 1; // the greater likelihood, the less the chance of getting the thingy $v = 2; $u1 = $u2 = 1; while ($v 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