Page 1 of 1

coding question...

Posted: Mon Jul 25, 2005 7:45 pm
by NoX
I would have put a better subject but i wasnt sure what to call it.

Im trying to do something thats probably simple but im rather new to php and figured id ask since i dont know anyone to talk to that knows php.

ive basicly want something to be executed by a random success rate which you can choose yourself depending on a value.

if i have this,

Code: Select all

if($star == 1){ $success = .5; }
 if($star == 2){ $success = .6; }
id have what i wanted to be executed 50% of the time for star 1 and 60% for star 2 which would be random.

so if u say had star 1, you would click on something and it would bring up that you did it (with success info) or you didnt (with fail info)

i hope that makes sence, if anyone can help me out it would be great.

hmm.. i think i confused myself :lol:

Posted: Mon Jul 25, 2005 9:02 pm
by timvw
So you need to:

1-) pick a random number... http://www.php.net/rand
2-) check if it's in the true segment...


Code: Select all

$chance = 50; // there is a 50% chance

$number = rand(0, 99);
if ($number < $chance)
{
  echo "you have won";
}
else
{
  echo "you loose";
}

Posted: Mon Jul 25, 2005 9:06 pm
by NoX
great thanks, after i posted it i was thinking about it and i figured thats what id have to do. i think im just tired today :)

thanks again.