<snip>
Thank you all for your help! I've added another condition to this program,
namely, in a range of 60, each 'random' number can only occur 10 times. I came
up with the following:
import random
series = []
for i in range(60):
temp = [random.randint(1, 6)]
while series[-2:-1] == series[-1:] == temp:
temp = [random.randint(1, 6)]
while series.count(temp[0])>= 10:
temp = [random.randint(1, 6)]
series.extend(temp)
print series
However, this also generates gems such as:
[4, 4, 3, 6, 3, 2, 6, 3, 4, 3, 4, 1, 4, 2, 4, 3, 4, 4, 6, 2, 1, 5, 5, 6, 5, 6,
5, 6, 3, 3, 1, 6, 6, 4, 1, 5, 2, 6, 6, 4, 2, 5, 3, 1, 5, 5, 2, 1, _2_, _2_,
_2_, 3, 3, 2, 1, 5, 1, 1, 5, 1]
[1, 4, 3, 1, 5, 3, 5, 1, 5, 6, 5, 3, 2, 6, 1, 4, 1, 5, 5, 2, 6, 2, 4, 1, 3, 1,
2, 1, 1, 3, 1, 6, 6, 3, 2, 3, 6, 4, 5, 6, 5, 6, 3, 6, 2, 4, 5, 3, 3, 4, 6, _4_,
_4_, _4_, 5, 4, _2_, _2_, _2_, _2_]
I thought this needed to become the following:
import random
series = []
for i in range(60):
temp = [random.randint(1, 6)]
print "Temp", i, ":", temp
while series[-2:-1] == series[-1:] == series:
if series.count(temp[0])>= 10:
temp = [random.randint(1, 6)]
series.extend(temp)
print series
But this just hangs whenever the while clause matches. I'm not sure what I'm
doing wrong here. I do know the random.shuffle() function, but I can't put my
conditions in there.