Random Percentages
Random Percentages
Okay, I'm trying to work out an attack scenario, and think I want to try using percentages, but have no idea how to make that happen.
I know I can use the rand(1,5) or whatever to choose between 1 and 5, but how would I create it so that it would randomly be between 1 and 5 percent instead?
I know I can use the rand(1,5) or whatever to choose between 1 and 5, but how would I create it so that it would randomly be between 1 and 5 percent instead?
- Sharlenwar
- Posts: 523
- Joined: Mon May 28, 2012 7:14 pm
Re: Random Percentages
Percentage is usually like 0.01 to 0.05 for 1%-5%. I'm not 100% sure if rand can take decimals Otherwise you can go RAND(1,5)/100.
Deep within the Void of Quasion, a creation.
**My Corner of the Web**
***NEW***GrindFest - My own PHP/MySQL game!
Sharlenwar's Adventures
Torn-City - Massively multiplayer online text based RPG
**My Corner of the Web**
***NEW***GrindFest - My own PHP/MySQL game!
Sharlenwar's Adventures
Torn-City - Massively multiplayer online text based RPG
Re: Random Percentages
Yeah you can do this any number of ways. Just do rand(1,100)/100 for the decimal, or rand(1,100) and then echo a % sign, depending on what you want to do.
Re: Random Percentages
What do you mean echo a % sign? I've been up for 36 hours lol... So what you said doesn't make sense...Xaos wrote:Yeah you can do this any number of ways. Just do rand(1,100)/100 for the decimal, or rand(1,100) and then echo a % sign, depending on what you want to do.
Code: Select all
$atk_player2 = rand(1,2)/100 * $_POST['dropdown'] * $attack_user['defense'];
echo '$atk_player2%';
What I really want to do I think, is to take the number of bullets they use and multiply that by the percent + their defense or something
So if they chose
1 bullet, it would be 1% * defense
2 bullet, it would be 2% * defense
3 bullet, it would be 3% * defense
ect....
Re: Random Percentages
Or my original thought....
if they choose between 1 and 5 bullets, h ave it randomly pick a % of the players health
if they choose between 6 and 10 bullets, have it reandomly pick a % of the players health
So something like it would be between a random 1% to 5% loss of the players health for so many bullets used... the more the higher percentage.
if they choose between 1 and 5 bullets, h ave it randomly pick a % of the players health
if they choose between 6 and 10 bullets, have it reandomly pick a % of the players health
So something like it would be between a random 1% to 5% loss of the players health for so many bullets used... the more the higher percentage.
Re: Random Percentages
% is based on 100% so
this will give you a random number 1 - 100.
if the number is 8. Its 8%
if the number is 3. Its 3% and jackpot.
Follow?
Code: Select all
$var = rand(1, 100);
if the number is 8. Its 8%
if the number is 3. Its 3% and jackpot.
Follow?
Re: Random Percentages
I guess I misread what was going on here.
1-5 random number
Based on what Xaos said.
1-5 random number
Based on what Xaos said.
Code: Select all
$rand_num = rand(1,5);
$atk_player2 = ($rand_num /100) * $_POST['dropdown'] * $attack_user['defense'];
echo "$atk_player2%";
echo "Your percentage ejaculation bonus was $rand_num%";
Re: Random Percentages
Okay, I end up with two percentages. Which one is what?Sim wrote:I guess I misread what was going on here.
1-5 random number
Based on what Xaos said.
Code: Select all
$rand_num = rand(1,5); $atk_player2 = ($rand_num /100) * $_POST['dropdown'] * $attack_user['defense']; echo "$atk_player2%"; echo "Your percentage ejaculation bonus was $rand_num%";
Code: Select all
1.2%Your percentage ejaculation bonus was 4%
Re: Random Percentages
Okay, I have this code written below now:
It showed that it was 6% one time but it was really .6%
Another time it was 12% but it was really 1.2%
How can I fix that accordingly? So it says it's 1.2% health loss instead of the 12 % that is isn't?
Thank you so very, very much for helping here.
Code: Select all
<?php
$rand_num = rand(1,2);
$atk_player = ($rand_num /100) * $_POST['dropdown'] * $row['defense'];
$atk_player2 = round($atk_player);
echo "$atk_player2%";
echo "Your percentage ejaculation bonus was $rand_num%";
$updatehpoints = "UPDATE users SET hpoints=hpoints - $atk_player2 WHERE username = '$_SESSION[username]'";
$query = mysqli_query($db_conx, $updatehpoints);
}}
?>
Another time it was 12% but it was really 1.2%
How can I fix that accordingly? So it says it's 1.2% health loss instead of the 12 % that is isn't?
Thank you so very, very much for helping here.
Re: Random Percentages
12% = .12. So in doing the math and formulas you would use .12, but in displaying to user, you would say
Code: Select all
echo "You lost " . $rand . "% of your health"';