str Mode

In str mode, string values are generated. The format of the command is as follows:

randog str [--length LENGTH] [--charset CHARSET] [--fmt FORMAT] [common-options]

randog str [--regex REGEX] [--fmt FORMAT] [common-options]

Warning

This string generation is not guaranteed to be cryptographically secure. In cases where there are security requirements, such as the generation of tokens for authentication, consider using secrets module or similar.

Arguments and Options

  • --length LENGTH (optional):

    • the length of generated strings. You can specify an integer such as --length 5 or a range such as --length 3:8.

  • --charset CHARSET (optional):

    • the characters which contained by generated strings.

  • --regex REGEX (optional):

    • the regular expression for generated string. It cannot be used with --length or --charset.

  • --fmt FORMAT (optional):

  • common-options

Examples

The simplest example is the following:

randog str

You can specify the length or/and characters as follows:

# generate a string of length 16
randog str --length 16

# generate a string of length 8 - 16, which uses chars "0123456789abcdef"
randog str --length 8:16 --charset 0123456789abcdef

Warning

This string generation is not guaranteed to be cryptographically secure. In cases where there are security requirements, such as the generation of tokens for authentication, consider using secrets module or similar.

Alternatively, you can specify a string to be generated by a regular expression.

# generate a string of length 10 - 20, which uses numeric chars and alphabets
randog str --regex '[a-zA-Z0-9]{10,20}'

Note

To generate strings using regular expressions, use the rstr package, which must be installed beforehand, e.g., by pip install rstr.

Warning

To generate strings using regular expressions, use the rstr package. If you use it, please review and follow the license terms of rstr.

Format: align, etc.

The output format can be specified in format specification mini-language as follows:

# output string such as '      zy7q'
randog str --length 4 --fmt '>10'