3 ms·
if you don't know the algorithm you could easily get it subtly wrong but the only method involved here is string.strip(), so i don't think this is an example o
by kragen 3y ago
if you don't know the algorithm you could easily get it subtly wrong
but the only method involved here is string.strip(), so i don't think this is an example of the problem you describe
import random
n = 100
ws = [line.strip() for line in open('/usr/share/dict/words')]
for i in range(n):
j = random.randrange(i, len(ws))
ws[i], ws[j] = ws[j], ws[i]
print(ws[i])
(did i fuck that up)
and yeah probably calling random.sample would be better. and usually import random is better than writing your own rng. but not always