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;
}
}
?>