thefollower Posted December 7, 2007 Share Posted December 7, 2007 Either my maths sucks (which it does normally) lol or I've got the logic wrong here cos the result isn't doing what its suppose to! Its meant to add a % ($X) to a value which is($AttackHit). $AttackHit = 3; $X = array(); $X[] = '2'; $X[] = '1'; $X[] = '5'; $X[] = '5'; $X[] = '3'; $XKey = array_rand($X); $x = $X[$XKey]; $TotalAttackHit = $AttackHit*($x/100); } Echo $TotalAttackHit; The echo shows "0", so I am not sure what happened. But what is meant to happen is the % which is $X is meant to be "added" ontop "AttackHit" which becomes $ToalAttackHit. It turns out as 0 all the time though. Link to comment https://forums.phpfreaks.com/topic/80700-rand-not-working/ Share on other sites More sharing options...
phpSensei Posted December 7, 2007 Share Posted December 7, 2007 try this $AttackHit = 3; $X = array('2','1','5','5','3'); $XKey = array_rand($X); $x = $X[$XKey]; $TotalAttackHit = $AttackHit*($x/100); } Echo $TotalAttackHit; Link to comment https://forums.phpfreaks.com/topic/80700-rand-not-working/#findComment-409349 Share on other sites More sharing options...
roopurt18 Posted December 7, 2007 Share Posted December 7, 2007 Your code never returns zero for me. I see you have a curly bracket in there; I'll wager that curly bracket goes with an if that never gets entered. Link to comment https://forums.phpfreaks.com/topic/80700-rand-not-working/#findComment-409356 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.