1

I am making a simple (terminal) slot machine project, in which 3 fruit names will be output in the terminal, and if they are all the same then the player wins.

I cannot figure out how to make a set probability that the player will win the round (roughly 40% chance for example). As of now I have:

     this->slotOne = rand() % 6 + 1;              // chooses rand number for designated slot
     this->oneFruit = spinTOfruit(this->slotOne); //converts rand number to fruit name

     this->slotTwo = rand() % 6 + 1;
     this->twoFruit = spinTOfruit(this->slotTwo);

     this->slotThree = rand() % 6 + 1;
     this->threeFruit = spinTOfruit(this->slotThree);

which picks a "fruit" based on the number, but each of the three slots has a 1 in 6 chance (seeing that there are 6 fruits). Since each individual slot has a 1/6 chance, overall the probability of winning is incredibly low.

How would I fix this to create better odds (or even better, chosen odds, changing the odds when desired)?

I thought of changing the second two spins to less options (rand()%2 for instance), but that would make the last two slots choose the same couple fruits every time.

The link to my project: https://github.com/tristanzickovich/slotmachine

Happy Hippo
  • 102
  • 9
  • See [this question](http://stackoverflow.com/questions/2649717/c-function-for-picking-from-a-list-where-each-element-has-a-distinct-probabili?rq=1) for some inspiration. – 500 - Internal Server Error Jan 14 '15 at 22:15
  • 1
    I think it's 1/36 %. The first spin is independent. The next two are dependent. 6/6*1/6*1/6=1/36. Which is still a mere 2.77 percent – Happy Hippo Jan 14 '15 at 22:21
  • @TristanZickovich: On a slot machine, how is the 2nd wheel dependent on the first? – Thomas Matthews Jan 14 '15 at 22:27
  • 1
    But the first spin can be anything. Then the next two have to be the same, so only the second two have 1/6, right? – Happy Hippo Jan 14 '15 at 22:27
  • @ThomasMatthews: it's dependent if you're looking for a matching number. Depending on what you get for the first, the second and third must follow to be a winner – Happy Hippo Jan 14 '15 at 22:29
  • In a 3 wheel slot machine, the wheels are independent of each other. This allows each wheel to display the same value, which ends up in a win. – Thomas Matthews Jan 14 '15 at 22:29

1 Answers1

6

Cheat.

Decide first if the player wins or not

const bool winner = ( rand() % 100 ) < 40 // 40 % odds (roughly)

Then invent an outcome that supports your decision.

if ( winner )
{
   // Pick the one winning fruit.
   this->slotOne = this->slotTwo = this->slotThree = rand() % 6 + 1;  
}
else
{
   // Pick a failing combo.
   do
   {
        this->slotOne = rand() % 6 + 1;    
        this->slotTwo = rand() % 6 + 1;    
        this->slotThree = rand() % 6 + 1;    
   } while ( slotOne == slotTwo && slotTwo == slotThree );
}

You can now toy with the player's emotions like the Vegas best.

Drew Dormann
  • 59,987
  • 13
  • 123
  • 180