[Haskell-cafe] How to select n random words from a file ...

Noon Silk noonslists at gmail.com
Sun Jun 10 15:21:43 CEST 2012


 I'm clearly new to haskell, and I suppose those is a basic question,
but after a bit of searching I've been unable to figure out the "best"
way to do this. I was first trying to find out how to, say, get a
random element from a list, but I'm starting to think that may not be
the best way (because list access isn't constant time, among other
reasons). So, I wonder if there is a more direct way to just get a
random word from a wordfile (i.e. one word per line) ... can anyone
suggest a method?

 Ideally I'd like to be able to adapt this to get n random words from
several files (i.e. randomly select n words from all files; i.e. just
read them into one merged array and choose from there?)

 Thanks for any advice ...

Noon Silk

Fancy a quantum lunch? https://sites.google.com/site/quantumlunch/

"Every morning when I wake up, I experience an exquisite joy — the joy
of being this signature."

More information about the Haskell-Cafe mailing list