random-strings-0.1.0.0: Generate random strings with specific qualities

Safe HaskellSafe
LanguageHaskell2010

Test.RandomStrings

Contents

Description

A way to generate random character strings for testing. Functions allow tuning of strings, setting the probability of alphabetic and upper-case characters in the resulting strings.

Hopefully this is useful for building test and benchmark cases that are more meaningful than the overly random strings generated by libraries like QuickCheck.

Note: Please don't use this to generate passwords!

Examples:

Generate a 10-letter word with 1 in 10 upper-case characters

word <- randomWord' randomASCII (1%10) 10

Generate a list of 500 strings from the printable ISO-8859-1 characters with random lengths beween 5 and 20 characters.

let iso_printable = randomString $ onlyPrintable randomChar8
strings <- randomStringsLen iso_printable (5,20) 500

-- benchmarks ...

Synopsis

Character generators

randomChar :: IO Char Source #

Generate a random Char

randomASCII :: IO Char Source #

Generate a random ASCII (7-bit) char in the printable range.

randomChar8 :: IO Char Source #

Generate a random ISO-8859-1 (8-bit) char

Specific character generators

onlyWith Source #

Arguments

:: (Char -> Bool)

predicate, like isAlpha

-> IO Char

random char generator, like randomChar or randomASCII or randomChar8

-> IO Char 

Random character passing a test

onlyPrintable :: IO Char -> IO Char Source #

Supply a random printable character.

onlyAlpha :: IO Char -> IO Char Source #

Generate a random alphabetic char.

onlyAlpha' Source #

Arguments

:: Rational

range 0 to 1; chance of being an upper

-> IO Char

random char generator; randomChar, randomASCII, randomChar8

-> IO Char 

Generate a random alphabetic char with a probability of being upper-case.

onlyAlphaNum :: IO Char -> IO Char Source #

Generate an alphanumeric char.

onlyUpper :: IO Char -> IO Char Source #

Generate a random upper-case letter.

onlyLower :: IO Char -> IO Char Source #

Generate a random lower-case letter.

randomClass Source #

Arguments

:: Rational

range 0 to 1; chance of using the first generator

-> IO Char

first generator; used if the random value is True

-> IO Char

second generator; used if the random value is False

-> IO Char 

Randomly generate one of two character types

String generators

randomWord Source #

Arguments

:: IO Char

random char generator; randomChar or randomASCII or randomChar8

-> Int

length

-> IO String 

Generate a random string of alphabetic characters.

randomWord' Source #

Arguments

:: IO Char

random char generator; randomChar or randomASCII or randomChar8

-> Rational

range 0 to 1; fraction of upper-case letters

-> Int

length

-> IO String 

randomString Source #

Arguments

:: IO Char

random char generator; eg. randomChar8 or onlyAlpha randomASCII

-> Int

length

-> IO String 

Generate a random string

randomString' Source #

Arguments

:: IO Char

random char generator; randomChar or randomASCII or randomChar8

-> Rational

range 0 to 1; fraction of alphabetic characters

-> Rational

range 0 to 1; fraction of upper-case letters

-> Int

length

-> IO String 

Generate a random string of printable characters with a balance of alphabetic and upper-case characters.

Sets of randomly generated strings

randomStrings Source #

Arguments

:: IO String

random string generator, eg. 'randomString randomAlpha 20'

-> Int

list length

-> IO [String] 

Generate a list of strings of uniform length.

randomStrings (randomString (onlyAlpha randomChar8) 20) 50

will build a list of 50 alphabetical strings, each 20 characters long.

randomStringsLen Source #

Arguments

:: (Int -> IO String)

random string generator, eg. randomString randomAlpha

-> (Int, Int)

range for string length

-> Int

list length

-> IO [String] 

Generate a list of strings of variable length.

Similar to randomStrings, but generates strings with random length. Example:

randomStringsLen (randomString' randomASCII (3%4) (1%8)) (10,30) 100

Returns a list of 100 strings that are between 10 and 30 characters, with 34 of them being alphabetical and 18 of those being upper-case.