randstr:   Random String Generator
1 Functions
randstr
randstr*
2 Pattern Syntax
3 Advanced Examples
4 License
8.18

randstr: Random String Generator🔗ℹ

Hugefiver

 (require randstr) package: randstr

A library for generating random strings based on regex-like patterns.

1 Functions🔗ℹ

procedure

(randstr pattern)  string?

  pattern : string?
Generate a random string based on the given pattern.

Examples:
(randstr "[a-z]{5}")
(randstr "[0-9][a-z]+")
(randstr "(abc|def)+")

procedure

(randstr* pattern n)  (listof string?)

  pattern : string?
  n : exact-positive-integer?
Generate a list of n random strings based on the given pattern.

Examples:

(randstr* "[0-9]{3}" 5)

2 Pattern Syntax🔗ℹ

The following pattern syntax is supported:

  • [abc] - Choose randomly from characters a, b, or c

  • [a-z] - Choose randomly from lowercase letters a through z

  • (abc|def) - Choose randomly between "abc" or "def"

  • a* - Zero or more of the preceding character

  • a+ - One or more of the preceding character

  • a? - Zero or one of the preceding character

  • . - Any character

3 Advanced Examples🔗ℹ

In addition to basic pattern matching, the library supports more complex patterns:

(randstr "[[:alpha:]]{5}")
(randstr "[[:digit:]]{3}")
(randstr "[[:alnum:]]{4}")
(randstr "[[:word:]]+")
(randstr "[[:upper:]0-9]+")
(randstr "[[:lower:]_]+")
(randstr "[[:alpha:]0-9]+")

4 License🔗ℹ

This project is licensed under the MIT License. See the "LICENSE" file for details.