In article <[email protected]>,
Nick Cash <[email protected]> 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!
--
https://mail.python.org/mailman/listinfo/python-list