vendredi 27 juillet 2018

trying to +1 to random.seed() for every loop

I'm working on a casino program that gets a bet ($1-$50) from the user, then pulls a slot machine to display a three-string combination of "7", "cherries", "bar", or "(space)". Certain combinations will trigger a bet multiplier, and the user will win back this amount. The run should look like this: ask user for bet, show user the pull and their winnings, then ask user for a new bet, display a new pull, and so on.

Right now, I have everything down except for a couple problems - I cannot make it so that the program generates a new random combination for each pull. Secondly, the main loop continues forever, printing the user's pull and winnings forever. Below is the method that generates either "7", "cherries", etc.

def rand_string(self):
    random.seed(0)
    # produces a number between 0 and 999
    test_num = random.randrange(1000)

    # precompute cutoffs
    bar_cutoff = 10 * TripleString.BAR_PCT
    cherries_cutoff = bar_cutoff + 10 * TripleString.CHERRIES_PCT
    space_cutoff = cherries_cutoff + 10 * TripleString.SPACE_PCT

    # bar = 38%, cherries = 40%, space = 7%, seven = 15%
    if test_num < bar_cutoff:
        return TripleString.BAR
    elif test_num < cherries_cutoff:
        return TripleString.CHERRIES
    elif test_num < space_cutoff:
        return TripleString.SPACE
    else:
        return TripleString.SEVEN

And here is the loop in main:

while(True):
if bet == 0: #a bet of $0 ends the program
    print("Please come again!")
    break
else:
    print("whirrr...and your pull is " +\
          object.pull())
    object.display(None)

I thought I could solve this by somehow adding 1 to random.seed() for each loop (we begin with random.seed(0), but for each new pull 1 is added so that random.seed(1) and so on), but I don't know how to go about doing this and I'm not even sure if it's doable. If someone could point out my mistakes here, that'd be great. (sorry if this makes no sense, I'm very new to Python).




Aucun commentaire:

Enregistrer un commentaire