slyte33 Posted November 13, 2009 Share Posted November 13, 2009 Basically there is an attacker and a defender. The Attacker has 1,000 agility, the Defender has 10,000 agility. The attacker should have a 10% chance of not missing(1,000/10,000=0.1(10%)) I've been at this for hours and hours, but cannot find a solution.. At first I thought...there is nothing hard about dividing 1,000 into 10,000 and making a player miss 90% of the time, but then I figured i'd need a: if ($? >= ?) { //miss } which gave me a problem Feedback on this would be much appreciated, thank you Quote Link to comment Share on other sites More sharing options...
corbin Posted November 13, 2009 Share Posted November 13, 2009 Well, you'll need an element of randomness. The first thing that comes to mind (because I've seen it before, not because I thought of it lol) is: $chance = 100*$agil1/$agil2; if(rand(1, 100) <= $chance) { //hit } Quote Link to comment Share on other sites More sharing options...
slyte33 Posted November 13, 2009 Author Share Posted November 13, 2009 Well, you'll need an element of randomness. The first thing that comes to mind (because I've seen it before, not because I thought of it lol) is: $chance = 100*$agil1/$agil2; if(rand(1, 100) <= $chance) { //hit } Thank you so much! Works perfectly Quote Link to comment Share on other sites More sharing options...
corbin Posted November 13, 2009 Share Posted November 13, 2009 No problem ;p. Quote Link to comment Share on other sites More sharing options...
PugJr Posted November 13, 2009 Share Posted November 13, 2009 Not sure how true this is, but mt_rand() is supposed to be faster and more randomly generated than rand(). Quote Link to comment Share on other sites More sharing options...
Tagg Posted November 18, 2009 Share Posted November 18, 2009 Not sure how true this is, but mt_rand() is supposed to be faster and more randomly generated than rand(). It used to be, but over the years it has gotten faster [than mt_rand()]. But it still is more random like you said. Quote Link to comment Share on other sites More sharing options...
corbin Posted November 18, 2009 Share Posted November 18, 2009 The reason it is more random is that the algorithm behind it takes into account microsecond (mt -> microtime). Thus, if you're only running it 1 time, the randomness is theoretically the same or at least almost the same. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.