title: JavaScript Slot Machine: What Is A Simple Algorithm For Picking A Winner?
body: <p>I'm developing a slot machine in JavaScript, and this slot machine has 3 reels.</p>
  
  <p>Each reel is identical and contains 4 symbols: A bar, a 7, a bell, and a grape. The bar is displayed on the reel one time, the 7 two times, the bell three times, and the grape four times - for a total of 10 symbols per reel. And each symbol corresponds with a number from 0 - 9:</p>
  
  <pre><code>| bar | -&gt; 9
  |  7  | -&gt; 8 
  |  7  | -&gt; 7
  | bell| -&gt; 6
  | bell| -&gt; 5
  | bell| -&gt; 4
  |grape| -&gt; 3
  |grape| -&gt; 2
  |grape| -&gt; 1
  |grape| -&gt; 0
  </code></pre>
  
  <p>I'm then randomly generating a number from 0 - 999, and based on that number I would like to potentially select a winner. For example, if the number is 999 that is three bars and the first jackpot, if the number is 210 that is three grapes and the fourth jackpot. If the number is 359 that is grape/bell/bar and no jackpot.</p>
  
  <p>I had created an if/else to select the winner but realized it does not take into account the second winning situation of 210:</p>
  
  <pre><code>if (number == 999) {
      // Jackpot 1
  } else if (number == 888) {
      // Jackpot 2
  } else if (number == 777) {
      // Jackpot 2
  } else if (number == 666) {
      // Jackpot 3
  } else if (number == 555) {
      // Jackpot 3
  } else if (number == 444) {
      // Jackpot 3
  } else if (number == 333) {
      // Jackpot 4
  } else if (number == 222) {
      // Jackpot 4
  } else if (number == 111) {
      // Jackpot 4
  } else if (number == 0) {
      // Jackpot 4
  } else {
      // No jackpot
  }
  </code></pre>
  
  <p>Does anyone have any ideas for how I might devise a simple algorithm for selecting a winner, as opposed to a bunch of if/else's? Also, there needs to be a total of 10 possible outcomes per reel, as the top jackpot should have a probability of 10^3 => 1 in 1,000.</p>