<commit_before>------------------------------------------------------------------------------
-- Standard Library: Random numbers
--
-- Suitable for use with Hugs 98
--
-- The code in this file draws heavily from several different sources,
-- including the implementations in previous Hugs and GHC implementations.
-- Much of this was done by <NAME>.  If there are mistakes here,
-- blame me.  The random number generation itself is based on a published
-- article by L'Ecuyer that was transliterated into Haskell by Lennart
-- Augustsson.  See the comments below for further details.
------------------------------------------------------------------------------

module Random(
	RandomGen(next, split),
	StdGen, mkStdGen,
	Random( random,   randomR,
		randoms,  randomRs,
		randomIO, randomRIO ),
	getStdRandom, getStdGen, setStdGen, newStdGen
  ) where

import IOExts  ( IORef, newIORef, writeIORef, readIORef,
		 unsafePerformIO
	       )
import Numeric ( showInt, showSigned, readDec )

-- The RandomGen class: ------------------------------------------------------

class RandomGen g where
   next  :: g -> (Int, g)
   split :: g -> (g, g)


-- An efficient and portable combined random number generator: ---------------
--
-- The June 1988 (v31 #6) issue of the Communications of the ACM has an
-- article by <NAME> called, "Efficient and Portable Combined
-- Random Number Generators".  Here is the Portable Combined Generator of
-- L'Ecuyer for 32-bit computers.  It has a period of roughly 2.30584e18.
-- 
-- Transliterator: <NAME>
-- sof 1/99 - code brought (kicking and screaming) into the new Random
-- world..
------------------------------------------------------------------------------

data StdGen = StdGen Int Int

mkStdGen	      :: Int -> StdGen
mkStdGen seed          = StdGen (s1+1) (s2+1)
                         where s       = abs seed
			       (q, s1) = s `divMod` 2147483562
			       s2      = q `mod` 2147483398

stdFromString         :: String -> (StdGen, String)
stdFromString s        = (mkStdGen num, rest)
	where (cs, rest) = splitAt 6 s
              num        = foldl (\a x -> x + 3 * a) 1 (map ord cs)<commit_msg>More H98 tracking; added RandomGen.genRange + default method for it<commit_after>------------------------------------------------------------------------------
-- Standard Library: Random numbers
--
-- Suitable for use with Hugs 98
--
-- The code in this file draws heavily from several different sources,
-- including the implementations in previous Hugs and GHC implementations.
-- Much of this was done by <NAME>.  If there are mistakes here,
-- blame me.  The random number generation itself is based on a published
-- article by L'Ecuyer that was transliterated into Haskell by Lennart
-- Augustsson.  See the comments below for further details.
------------------------------------------------------------------------------

module Random(
	RandomGen(next, split),
	StdGen, mkStdGen,
	Random( random,   randomR,
		randoms,  randomRs,
		randomIO, randomRIO ),
	getStdRandom, getStdGen, setStdGen, newStdGen
  ) where

import IOExts  ( IORef, newIORef, writeIORef, readIORef,
		 unsafePerformIO
	       )
import Numeric ( showInt, showSigned, readDec )

-- The RandomGen class: ------------------------------------------------------

class RandomGen g where
   genRange :: g -> (Int, Int)
   next     :: g -> (Int, g)
   split    :: g -> (g, g)
   
   genRange _ = (minBound,maxBound)


-- An efficient and portable combined random number generator: ---------------
--
-- The June 1988 (v31 #6) issue of the Communications of the ACM has an
-- article by <NAME> called, "Efficient and Portable Combined
-- Random Number Generators".  Here is the Portable Combined Generator of
-- L'Ecuyer for 32-bit computers.  It has a period of roughly 2.30584e18.
-- 
-- Transliterator: <NAME>
-- sof 1/99 - code brought (kicking and screaming) into the new Random
-- world..
------------------------------------------------------------------------------

data StdGen = StdGen Int Int

mkStdGen	      :: Int -> StdGen
mkStdGen seed          = StdGen (s1+1) (s2+1)
                         where s       = abs seed
			       (q, s1) = s `divMod` 2147483562
			       s2      = q `mod` 2147483398

stdFromString         :: String -> (StdGen, String)
stdFromString s        = (mkStdGen num, rest)
	where (cs, rest) = splitAt 6 s
              num        = foldl (\a x -> x + 3 * a) 1 (map ord cs)
{'fraction_non_alphanumeric': 0.21681316204642775, 'fraction_numerical': 0.023439260761775976, 'mean_word_length': 1.6929611650485437, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2916265', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1182, 'n_words': 483}