Having Issues with Random (Python)
Hi, so I was bored and started working on a python program that gives you random Math problems and when I run the program, sometimes the code just randomly fails to actually pick a random choice from the operation array which is literally just something I chose to add for weight of operations and chance.
Code should 100% of the time pick a random item from the
Code most of the time works, but sometimes gives me an error that says something like
int is out of range
I'm not certain about this because it's hard to recreate this error, but you may occasionally be out of range due to how line 79 is written:
operation = pool[random.randint(1,random.randint(0,len(pool)))]
You're calling 2 separate random integer functions. The second embedded one is a range from
whatever. On occasion it may select
0 as the random number. Then, it uses this random number in the first random selection using a range from
<second random number>. In this case, you would be asking it to pick a random number between
0, which I think will cause a range error. Try changing the range be something equal to or greater than 1 for the second embedded random number generator:
operation = pool[random.randint(1,random.randint(1,len(pool)))]
Hopefully that fixes your issue.