Note that there are some explanatory texts on larger screens.

plurals
  1. PORandomly generate numbers based on stock in MySQL database
    primarykey
    data
    text
    <p>Hi guys I need a bit of help with a script I am making in Php, currently it is setup as a slot style game where users can pay a bit of money and 3 random number are generated, each number links up to a prize they can win. Match 3 and win said prize. </p> <p>Unfortunately as I will not always have every item in stock to give away as a prize I need a way to check through each number and make sure it is in stock</p> <p><code>$stock = $conn -&gt; query('SELECT DISTINCT ItemID FROM codes WHERE Available = 1');</code></p> <p>And if it is in stock add it in an algorithm which will randomly pick the 3 numbers</p> <p>Currently I have a setup like so</p> <pre><code>function generate_numbers(){ global $numbers; $numbers = array( '0' =&gt; rand(1,2), '1' =&gt; rand(1,2), '2' =&gt; rand(1,2) ); display_numbers(); } </code></pre> <p>Which generates numbers based upon two variables and each number links to a prize, obviously it does not take into account which numbers are in stock which will lead to me giving out prizes I dont have, and it does not allow for an edge</p> <p>I need a simple way to check if an item is in stock and if it is stocked it is added to a list of prizes that can be won, I need it to have an edge so some prizes will appear (a lot) more frequently than others based on simple values like code X has a 0.25% chance of appearing and cody Y has a 50% chance of appearing.</p> <p>If i set it up with a larger range of numbers ...</p> <pre><code>function generate_numbers(){ global $numbers; $numbers = array( '0' =&gt; rand(1,100), '1' =&gt; rand(1,100), '2' =&gt; rand(1,100) ); display_numbers(); } </code></pre> <hr> <pre><code>if (($numbers[0] &gt; 0) &amp;&amp; ($numbers[0] &lt; 40)){ echo "you win prize x"; else if (($numbers[0] &gt; 40) &amp;&amp; ($number[0] &lt; 50)){ echo "you win prize y"; else { echo "you win prize z"; } </code></pre> <p>...I am still left either giving out prizes I do not have - or I could add a embedded if else to check if a code is stocked, if it is give it out and if it isn't either give no prize or give a default prize.</p> <p>But this will mean that the more codes I have in stock the higher chance they have of being given which I don't want to do I really want it to be completely fair with predefined odds..</p> <p>So hopefully all that makes sense it's not an overly complex problem but I think quite an unusual one</p> <p>Thanks for reading and I look forward to hearing your ideas</p> <p>Luke</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload