Zach Lederman
Zach Lederman

Reputation: 1

How to make random.randint() more random

So I am writing my first program and it started as a just a something that rolls random dice values but I expanded it to and its a lot more fun.The problem I am having is that sometimes this function

def mathproblem(stuff): 

    if stuff == '1': 
        probuno=int(raw_input("can you solve: sqrt(169)+4")) 
        if probuno==17: 
            print('correct you may proceed') 
            rollify=True 
        else: 
            rollify=False 
    elif stuff=='2': 
        probdos=int(raw_input("can you solve: 47.9+36-14.8")) 
        if probdos==69.1: 
            print('YEEEET') 
            rollify=True 
        else: 
            print('you filthy wanker') 
            rollify=False 
    elif stuff == '3': 
        probtres=int(raw_input("can you solve: 32^2 -sqrt(625)")) 
        if probtres==399: 
            print('WOOOO') 
            rollify=True 
        else: 
            print('Wow... that was awful') 
            rollify=False 
    elif stuff=='4': 
        probquatro=int(raw_input("can you solve: ln(1)-e^0")) 
        if probquatro==-1: 
            print('MISSION ACCOMPLISHED') 
            rollify=True 
        else: 
            print('your parents probably hate you') 
            rollify=False 

    elif stuff=='5': 
        probcinco=(raw_input("can you solve: sqrt(-1)")) 
        if probcinco=='i': 
            print('wow you must be a genius') 
            rollify=True 
        else: 
            print('L') 
            rollify=False 

which gets used here

elif guess>rand: 
   print('HALT! YOU MAY PROCEED ONLY IF YOU...') 

    mathproblem(oof) 

and oof=random.randint(min,max) so every few times It sends the same problem over and over again, is there any way I can make this more random? edit: sorry for the teenager edginess ;)

Upvotes: 0

Views: 397

Answers (1)

SpoonMeiser
SpoonMeiser

Reputation: 20417

"More random" is definitely not what you're asking for.

But I believe that the behaviour you want is something like:

def not_really_random(r_min, r_max):
    seq = range(r_min, r_max+1)
    while True:
        random.shuffle(seq)
        for n in seq:
            yield n


for oof in not_really_random(a, b):
    mathproblem(oof)

Which will basically cycle through all the different problems in random orders (with a slight chance that after going through all the problems, it's start again at the last problem you saw)

Upvotes: 1

Related Questions