coding question...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
NoX
Forum Newbie
Posts: 2
Joined: Mon Jul 25, 2005 7:33 pm

coding question...

Post 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:
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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";
}
NoX
Forum Newbie
Posts: 2
Joined: Mon Jul 25, 2005 7:33 pm

Post 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.
Post Reply