ninetynine-1.3.0: Ninety-Nine Haskell Problems
CopyrightCopyright (C) 2021 Yoo Chung
LicenseGPL-3.0-or-later
Maintainerdev@chungyc.org
Safe HaskellSafe-Inferred
LanguageGHC2021

Problems.P23

Description

Part of Ninety-Nine Haskell Problems. Some solutions are in Solutions.P23.

Synopsis

Documentation

randomSelect :: RandomGen g => [a] -> Int -> g -> ([a], g) Source #

Extract a given number of randomly selected elements from a list.

Also return a new random number generator so that callers can avoid reusing a sequence of random numbers.

Examples

>>> fst $ randomSelect "abcdefgh" 3 $ mkStdGen 111
"chd"
>>> take 5 $ unfoldr (Just . randomSelect [1..100] 3) $ mkStdGen 111
[[11,19,76],[63,49,10],[75,42,12],[20,48,78],[40,94,86]]
>>> fst . randomSelect "abcdefgh" 3 <$> newStdGen
"ebf"