Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

choosing a random line from a file in haskell

Name: Anonymous 2009-01-20 3:35

is there any way to do it that's not slow as fuck?

Name: Anonymous 2009-01-20 3:57

>>1
Yes. Iterate through the file, each time choosing whether to keep the current choice or choose the current line instead. The first line is 1 likely to be picked. The second is 1/2 likely. The third is 1/3 likely. The fourth is 1/4 likely. The nth is 1/n likely. When you run out of lines, return the current choice.

Whether this is slow as fuck is a matter of opinion, of course. Disk access is slow as fuck.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List