What is an efficient way to randomize the order of something, for example characters in a string or places in an array, without repeating anything before you ran trough all characters/arrayplaces?
>>8
With the right type signature, >>6 is actually O(n) if use it on a DiffArray.
import Monad
import Random
import Data.Array.IArray
randomize :: (IArray a e, Enum i, Random i, Ix i) => a i e -> IO (a i e)
randomize array =
foldM step array $ reverse [lo..hi]
where step a i = fmap (swap a i) $ randomRIO (lo, i)
swap a i j = a // [(j, a!i), (i, a!j)]
(lo, hi) = bounds array
Array primes i and a port of emacs for windows take extra care to read step 23 in this post hated my guts from day one then write a command that records a set of classes whose behaviour depends too much on the fly with simple javascript 3 Firefox is not financed by evil tyrannical corporations intent on abusing their monopolies google mozilla 4.
Name:
Trollbot90002009-07-01 8:07
The entire script on one line but that should only be done in the most simple.
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy