<commit_before>{-|

This module exposes the @/dev/urandom@ device as a PRG for the raaz
libraries.

-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TypeFamilies               #-}
module Raaz.System.Random
       ( SystemPRG
       ) where

import System.IO (openBinaryFile, Handle, IOMode(ReadMode)
                 , BufferMode(NoBuffering), hSetBuffering
                 )

import Raaz.Core.ByteSource (ByteSource)
import Raaz.Core.Random     (PRG(..))


-- | The system wide pseudo-random generator. Many systems provide
-- high quality pseudo-random generator within the system like for
-- example the @/dev/random@ file on a posix system. This type
-- captures such a pseudo-random generator. The source is expected to
-- be of high quality, albeit a bit slow due to system call overheads.
newtype SystemPRG = SystemPRG Handle deriving ByteSource

instance PRG SystemPRG where
  type Seed SystemPRG = ()

  newPRG _ = do h <- openBinaryFile "/dev/urandom" ReadMode
                hSetBuffering h NoBuffering
                return $ SystemPRG h
  reseed _ _ = return ()<commit_msg>fix documentations in R.System.Random<commit_after>{-|

This module exposes the high quality cryptographic pseudo-random
generator exposed by the system.

-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TypeFamilies               #-}
module Raaz.System.Random
       ( SystemPRG
       ) where

import System.IO (openBinaryFile, Handle, IOMode(ReadMode)
                 , BufferMode(NoBuffering), hSetBuffering
                 )

import Raaz.Core.ByteSource (ByteSource)
import Raaz.Core.Random     (PRG(..))


-- | The system wide pseudo-random generator. Many systems provide
-- high quality pseudo-random generator within the system like for
-- example the @\/dev\/urandom@ file on a posix system. This type
-- captures such a pseudo-random generator. The source is expected to
-- be of high quality, albeit a bit slow due to system call overheads.
-- You do not need to seed this PRG and hence the associated type
-- @`Seed` `SystemPRG`@ is the unit type @()@.
newtype SystemPRG = SystemPRG Handle deriving ByteSource

instance PRG SystemPRG where
  type Seed SystemPRG = ()

  newPRG _ = do h <- openBinaryFile "/dev/urandom" ReadMode
                hSetBuffering h NoBuffering
                return $ SystemPRG h
  reseed _ _ = return ()
{'fraction_non_alphanumeric': 0.0830860534124629, 'fraction_numerical': 0.0, 'mean_word_length': 2.8562091503267975, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1988291', 'n_tokens_mistral': 689, 'n_tokens_neox': 668, 'n_words': 246}