firstrandom = random.randint(1,2)
secondrandom = random.randint(1,2)
I just need the secondrandom
variable to not equal the firstrandom
variable, but I don't know how to.
firstrandom = random.randint(1,2)
secondrandom = random.randint(1,2)
I just need the secondrandom
variable to not equal the firstrandom
variable, but I don't know how to.
Some potential options:
1
or 2
, just make secondrandom = 1 + (firstrandom % 2)
.randint
in a loop and only exit the loop when the value is different from firstrandom
.random.sample
of the allowed values.You could try this function, it returns a pair of two random integers that are not equal to each other:
import random
def randomPair(start, stop):
n1 = random.randint(start, stop)
n2 = random.randint(start, stop)
if start!=stop:
while n1 == n2: n2 = random.randint(start, stop)
return n1, n2