Hacker News new | past | comments | ask | show | jobs | submit login

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




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: