string-random-0.1.4.1: A library for generating random string from a regular experession
CopyrightCopyright (C) 2016- hiratara
LicenseGPL-3
Maintainerhiratara@cpan.org
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Text.StringRandom

Description

Generate a random character string that matches the given regular expression. This library ported String_random.js to Haskell.

    
    import Text.StringRandom

    main = do
      ymd <- stringRandomIO "20\d\d-(1[0-2]|0[1-9])-(0[1-9]|1\d|2[0-8])"
      print ymd -- "2048-12-08" etc.

See String_random.js

As with this package, there are random-strings in packages that generate random strings, but this module is superior in the following respects.

  • The format of the string to be generated using regular expressions
  • You can change the random number generator (e.g. tf-random package)
  • With pure calculation without using IO monad.
Synopsis

Documentation

stringRandomIO :: Text -> IO Text Source #

The stringRandomIO function generates random strings that match the given regular expression. Regular expression is specified by Text type. This function internally uses the random number generator generated by newStdGen.

stringRandom :: RandomGen g => g -> Text -> Text Source #

The stringRandom function uses a specified random number generator to generate a random string that matches a given regular expression. An exception is raised if the regular expression can not be parsed.

stringRandomWithError :: RandomGen g => g -> Text -> Either String Text Source #

The stringRandomWithError function behaves like the stringRandom function, but notifies the error through the Either monad.