Work to out a condition for my program
<p>I need a little help with a program/script I am making for a slot style game, the idea is there will be 3 numbers randomly generated and each will correspond to a prize you can win, there will be a limited number of prizes and so each code (which will be sent out as the prize) will have to be checked to make sure it is in stock, if it is not in stock it will not be added to the draw. </p>

<p>So far I have my script checking if a code is in stock and if it is it adds the number to an array which I will then check through a switch and case </p>

<p>But I am not sure how to setup the switch and case, I thought about adding a set number to the 'pot' which will then be used with the 3 randomly generated numbers</p>

<pre><code>$number1 = rand(0,$pot);
</code></pre>

<p>But doing it this way I would have to setup a statement whereby I would check each number and if it was in a certain range ie</p>

<pre><code>if (($number1 &gt; 150) &amp;&amp; ($number1 &lt; 349)){
// You win this prize
}
else if (($number 1 &gt; 350) &amp;&amp; ($number1 &lt; 499)){
// You win this prize
}
else {
//You win this prize
}
</code></pre>

<p>But obviously this method would only work if all codes were in stock because if they weren't I would be giving out prizes I don't have</p>

<pre><code>function generate_numbers(){
global $numbers;
$numbers = array(
    '0' =&gt; rand(1,4),
    '1' =&gt; rand(1,4),
    '2' =&gt; rand(1,4)
);
display_numbers();
}
</code></pre>

<p>This generates the numbers currently but works on just 4 variables so code a = the value of 1 code b = value of 2 etc</p>

<pre><code>//SETUP VARIABLES
$num1; $num2; $num3;
//SET VARIABLE VALUES
function setup_variables(){
global $num1, $num2, $num3, $numbers;
    $num1 = $numbers[0];
    $num2 = $numbers[1];
    $num3 = $numbers[2];
    result();
}
</code></pre>

<p>This converts the array into single variables, it might not be the suggested method but I can change it if needs be</p>

<pre><code>function result(){
global $num1, $num2, $num3;
    if ($num1 == $num2 &amp;&amp; $num1 == $num3){
        if ($num1 == 1){
            $_SESSION['prize'] = 1;
            header("Location: win.php");
        }
        else if ($num1 == 2){
            $_SESSION['prize'] = 2;
            header("Location: win.php");
        }
        else if ($num1 == 3){
            $_SESSION['prize'] = 3;
            header("Location: win.php");
        }
        else{
            $_SESSION['prize'] = 0;
        }
    }

    else{
        $_SESSION['prize'] = 0;
    }
}
</code></pre>

<p>This checks if the numbers match, if they do then it checks which number $num1 was and relays that to a prize that can be won using <code>$_SESSION['prize']</code></p>

<p>But as you can see it works on single numbers I would rather it work on a range of numbers so I can add variation and chance to the game, with certain prizes appearing more often than others</p>

<p>On the next page it simply queries the database based on the data given through $_SESSION['prize'] which is equal to a ItemID in the database and shows the code on screen + email it to the winner</p>

<p>TLDR : </p>

<p>Basically I want a way to display a written code based upon if the code is Available (Boolean database value) I do not want to display codes that are not Available and so they should be excluded from the script entirely and each code should have a different chance of winning, more valuable codes having a lower chance of appearing, less valuable codes having a higher chance.</p>

<p>Basically this is a php version of Slots but slots based on current stock </p>
