Generate random numbers without repeating a value: Difference between revisions

(→‎{{header|Haskell}}: Added a Haskell solution.)
Line 414:
import Data.Ord (comparing)
import System.Random (randomRIO)
 
n = 20
 
let rnd = randomRIO (0, 1) :: IO Double
 
main :: IO ()
main = do
rank <- replicateM n rnd
let rnd = randomRIO (0, 1) :: IO Double
>>= (print $. sndfmap <$>fst . sortOn fstsnd (zip. rankzip [1 .. n])</lang>
n = 20
rank <- replicateM n rnd
print $ snd <$> sortOn fst (zip rank [1 .. n])</lang>
{{Out}}
For example:
9,655

edits