Jump to content

Random number


Cruisecar

Recommended Posts

No, I will input a number - 0-100% and I need the script to return true or false based on the percentage.

Percentage = 50% - 1/2 chance of it returning true,
Percentage = 90% - 9/10 chance of it returning true,

I think that should sum it up :D Thanks for the reply.
Link to comment
Share on other sites

Hmmm...then why the title? :-P

Also...you are being just a tad vague. What conditions need to be met in order for it to return true/false? What will determine the precentage? Are you just entering whole numbers which will represent a %? Or are these numbers an actual percentage of something? You would need to know that, in order for us to help point ya in the right direction. Just a small example but...you can do something like:

[code]<?php

  $ognumber = $_POST['number'];
  //Or Whatever Method You're Using To Get This Value

  $percent = ($ognumber / 100);

  if($percent  > .49)

  {echo"At Least 50%";}

  else

  {echo"Less Than Half, Mate.";}

?>[/code]
Link to comment
Share on other sites

Okay, i'll attempt to re-explain, I guess I did it kind of crappy.

I will have whole numbers, 0-100, and based upon those numbers I need a 1 or 0. So say the number was 40, there would be a 40/100 chance the script would return 1/true.
Link to comment
Share on other sites

I see...so you are not really looking for a random result...but rather, a result based on probablity? And you will be somehow defining the value (Or percent) of this probablity? (Example 5/10 = 50% chance the result will be returned as "true")

Correct?
Link to comment
Share on other sites

hi, i noticed caeser hasnt replied, so ill try n help
[code]
function chance($input) {
  $rand= rand(0, 100) //get a number, 0 - 100
  if($rand > $input) {
/*if the number is more than random then its outside the percentage. e.g. $rang = 80  and $input = 60 then the rand is part of the 40%.*/
    return 1; //outside the chance%
  } else {
    return 0; //inside the chance%
  }
}
[/code]

im not 100% sure how you return values in PHP, ive kinda forgotten :P. but that should work good :)
Link to comment
Share on other sites

[!--quoteo(post=371725:date=May 5 2006, 11:18 PM:name=Cruisecar)--][div class=\'quotetop\']QUOTE(Cruisecar @ May 5 2006, 11:18 PM) [snapback]371725[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Your a genious, I knew all of the stuff you said - I just didn't piece it together. Thankyou!
[/quote]

happy to help :D if you can find the solved button, using it is much appreciated here!
Link to comment
Share on other sites

[!--quoteo(post=371726:date=May 5 2006, 11:19 PM:name=Mattyspatty)--][div class=\'quotetop\']QUOTE(Mattyspatty @ May 5 2006, 11:19 PM) [snapback]371726[/snapback][/div][div class=\'quotemain\'][!--quotec--]
happy to help :D if you can find the solved button, using it is much appreciated here!
[/quote]

Erm, where is it?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.