Generate random numbers without repeating a value: Difference between revisions
Generate random numbers without repeating a value (view source)
Revision as of 16:33, 14 April 2022
, 2 years ago→{{header|Haskell}}
(→{{header|Haskell}}: Added a Haskell solution.) |
|||
Line 414:
import Data.Ord (comparing)
import System.Random (randomRIO)
main :: IO ()
main =
▲ let rnd = randomRIO (0, 1) :: IO Double
▲ n = 20
▲ rank <- replicateM n rnd
▲ print $ snd <$> sortOn fst (zip rank [1 .. n])</lang>
{{Out}}
For example:
|