>>> 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.
>>> 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.
>>> 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.
>>> randomRIO (2020, 2100) :: IO Int 2028Similar 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
>>> import System.Random.Stateful >>> let pureGen = mkStdGen 137 >>> g <- newIOGenM pureGen >>> randomRM (1, 100) g :: IO Int 52You can use type applications to disambiguate the type of the generated numbers:
>>> :seti -XTypeApplications >>> randomRM @Int (1, 100) g 2