lsm-tree-1.1.1.0: Log-structured merge-trees
Safe HaskellSafe-Inferred
LanguageGHC2021

Database.LSMTree.Extras.Random

Synopsis

Sampling from uniform distributions

withoutReplacement :: Ord a => StdGen -> Int -> (StdGen -> (a, StdGen)) -> [a] Source #

withReplacement :: StdGen -> Int -> (StdGen -> (a, StdGen)) -> [a] Source #

Sampling from multiple distributions

frequency :: [(Int, StdGen -> (a, StdGen))] -> StdGen -> (a, StdGen) Source #

Chooses one of the given generators, with a weighted random distribution. The input list must be non-empty, weights should be non-negative, and the sum of weights should be non-zero (i.e., at least one weight should be positive).

Based on the implementation in QuickCheck.

Shuffling

shuffle :: [a] -> StdGen -> [a] Source #

Create a random permutation of a list.

Based on the implementation in QuickCheck.

Generators for specific data types

randomByteStringR :: (Int, Int) -> StdGen -> (ByteString, StdGen) Source #

Generates a random bytestring. Its length is uniformly distributed within the provided range.

Compatibility

splitGen_compat :: StdGen -> (StdGen, StdGen) Source #

Alternative to splitGen that is also compatible with versions of random<1.3

Uses split on random<1.3, and splitGen on random>=1.3. The former function is deprecated on random>=1.3.

uniform_compat :: (Uniform a, RandomGen g) => g -> (a, g) Source #

Alternative to uniform that is also compatible with versions of random<1.3

The order of type variables is different on randomand random=1.3. This is inconvenient for type application, so we use this compatibility function to ensure that the type variables always have the same ordering.