Q:

Percentage for event to happen PHP

My question is: if I have 2 variables, for example a=70 b=30 70 and 30 mean percentages for event to happen, how can make php script to simulate this chanсes of dropping variable 'a' or 'b'.
Example:
a=70
b=30

So if i start the php script i have 70% chance to see 'a' and 30% to see 'b'.
Sorry for bad description of my question, I haven't done this before.

A:

Generally, for natural numbers a>0 and b>0
if(mt_rand(1,$a+$b)>$a){
    echo 'b';
} else {
    echo 'a';
}

