[Tutor] reading random line from a file
Luke Paireepinart
rabidpoobear at gmail.com
Thu Jul 19 21:05:20 CEST 2007
bhaaluu wrote:
> Greetings,
> Thanks for including the complete source code!
> It really helps to have something that works to look at.
> I modified an earlier version of this to run on my
> computer (GNU/Linux; Python 2.4.3).
>
I think the best strategy for this problem would be to build an index of
the offset of the start of each line, and then randomly select from this
list.
that makes each line equally probable, and you can set up your class so
that the index is only built on the first call to the function.
-Luke
More information about the Tutor
mailing list