randomR

Takes a range (lo,hi) and a pseudo-random number generator g, and returns a pseudo-random value uniformly distributed over the closed interval [lo,hi], together with a new generator. It is unspecified what happens if lo>hi, but usually the values will simply get swapped.
>>> let gen = mkStdGen 26

>>> fst $ randomR ('a', 'z') gen
'z'

>>> fst $ randomR ('a', 'z') gen
'z'
For continuous types there is no requirement that the values lo and hi are ever produced, but they may be, depending on the implementation and the interval. There is no requirement to follow the Ord instance and the concept of range can be defined on per type basis. For example product types will treat their values independently:
>>> fst $ randomR (('a', 5.0), ('z', 10.0)) $ mkStdGen 26
('z',5.22694980853051)
In case when a lawful range is desired uniformR should be used instead.
Takes a range (lo,hi) and a pseudo-random number generator g, and returns a pseudo-random value uniformly distributed over the closed interval [lo,hi], together with a new generator. It is unspecified what happens if lo>hi, but usually the values will simply get swapped.
>>> let gen = mkStdGen 26

>>> fst $ randomR ('a', 'z') gen
'z'

>>> fst $ randomR ('a', 'z') gen
'z'
For continuous types there is no requirement that the values lo and hi are ever produced, but they may be, depending on the implementation and the interval. There is no requirement to follow the Ord instance and the concept of range can be defined on per type basis. For example product types will treat their values independently:
>>> fst $ randomR (('a', 5.0), ('z', 10.0)) $ mkStdGen 26
('z',5.22694980853051)
In case when a lawful range is desired uniformR should be used instead.
Takes a range (lo,hi) and a pseudo-random number generator g, and returns a pseudo-random value uniformly distributed over the closed interval [lo,hi], together with a new generator. It is unspecified what happens if lo>hi, but usually the values will simply get swapped.
>>> let gen = mkStdGen 2021

>>> fst $ randomR ('a', 'z') gen
't'

>>> fst $ randomR ('z', 'a') gen
't'
For continuous types there is no requirement that the values lo and hi are ever produced, but they may be, depending on the implementation and the interval. There is no requirement to follow the Ord instance and the concept of range can be defined on per type basis. For example product types will treat their values independently:
>>> fst $ randomR (('a', 5.0), ('z', 10.0)) $ mkStdGen 2021
('t',6.240232662366563)
In case when a lawful range is desired uniformR should be used instead.
Get a random object within a (inclusive) range with a uniform distribution.
A variant of randomRM that uses the global pseudo-random number generator globalStdGen
>>> randomRIO (2020, 2100) :: IO Int
2028
Similar to randomIO, this function is equivalent to getStdRandom randomR and is included in this interface for historical reasons and backwards compatibility. It is recommended to use uniformRM instead, possibly with the globalStdGen if relying on the global state is acceptable.
>>> import System.Random.Stateful

>>> uniformRM (2020, 2100) globalStdGen :: IO Int
2044
Plural variant of randomR, producing an infinite list of pseudo-random values instead of returning a new generator.
Generates a pseudo-random value using monadic interface and Random instance.

Examples

>>> import System.Random.Stateful

>>> let pureGen = mkStdGen 137

>>> g <- newIOGenM pureGen

>>> randomRM (1, 100) g :: IO Int
52
You can use type applications to disambiguate the type of the generated numbers:
>>> :seti -XTypeApplications

>>> randomRM @Int (1, 100) g
2
Generate random Integral in [0, x] range.
Return a random hand that is a Royal Flush
Returns a random standard playing card rank, with Ace low.
Returns a random standard playing card from a range, with Ace low.
Similar to RandomO. However, a reversed copy of the list of shuffled Proposals is appended such that the resulting Markov chain is reversible. Note: the total number of Proposals executed per cycle is twice the number of RandomO.
Takes a range (lo,hi) and a random number generator g, and returns a computation that returns a random value uniformly distributed in the closed interval [lo,hi], together with a new generator. It is unspecified what happens if lo>hi. For continuous types there is no requirement that the values lo and hi are ever produced, but they may be, depending on the implementation and the interval. See randomR for details.
Plural variant of getRandomR, producing an infinite list of random values instead of returning a new generator. See randomRs for details.
Produce a random value at every tick, within a range given per tick.
Produce a random value at every tick, within a range given once.