Use itertools
, specifically islice
and cycle
.
start = random.randint(0, len(Choice) - 1)
list(islice(cycle(Choice), start, start + n))
cycle(Choice)
is an infinite sequence that repeats your original list, so that the slice start:start + n
will wrap if necessary.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…