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: >>13 2009-01-20 7:45

Fuck.

import System
import Random
import qualified Data.ByteString.Char8 as Char8

main = do file <- fmap Char8.lines . Char8.readFile . head =<< getArgs
          Char8.putStrLn . (file !!) =<< randomRIO (0, length file)


Compiled with -O -optc-O3.

Time results with a 86104 line file (just 1 run, their speed doesn't vary that much):

real    0m0.176s
user    0m0.128s
sys     0m0.028s

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