Code golf challenge: XKCD 936 passwords
Roy Smith
roy at panix.com
Wed Oct 9 20:29:00 EDT 2013
In article <mailman.901.1381334893.18130.python-list at python.org>,
Nick Cash <nick.cash at npcinternational.com> wrote:
> >> # Python-2, sorry
> >> import os
> >> print list(set(open('/usr/share/dict/words')))[os.getpid():][:4]
>
> > So that steps by your pid?
>
> Not really. It seems to rely on list(set(...)) kinda randomizing order...
> which is definitely not safe without hash randomization.
Exactly. I *did* preface this with:
>>> If you're willing to accept a sub-optimal random number generator:
[Nick, again]
> But this brings up an interesting concept... if we can assume Python 2.7 with
> the -R flag, or Python 3.3+, I think we do get true pseudo-randomization out
> of list(set(...))... which means we can trim some!
>
> print(list(set(open('/usr/share/dict/words')))[:4])
Excellent! I didn't know about -R before this, so not only has this
been fun, it's been educational too!
More information about the Python-list
mailing list