https://github.com/thomasleplus/randalf
Generates a random string of desired length using chosen alphabet.
https://github.com/thomasleplus/randalf
Last synced: 7 months ago
JSON representation
Generates a random string of desired length using chosen alphabet.
- Host: GitHub
- URL: https://github.com/thomasleplus/randalf
- Owner: thomasleplus
- License: apache-2.0
- Created: 2025-08-14T15:49:46.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-09-27T10:51:28.000Z (7 months ago)
- Last Synced: 2025-09-27T12:26:50.420Z (7 months ago)
- Language: Python
- Size: 93.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Randalf
The wizard of randomness :mage_man:
Generates a random string of desired length using chosen alphabet.
[](https://github.com/leplusorg/randalf/actions?query=workflow:"FIXME")
[](https://pypi.python.org/pypi/randalf)
[](https://pypi.python.org/pypi/randalf)
[](https://github.com/leplusorg/randalf/actions?query=workflow:"CodeQL")
[](https://bestpractices.coreinfrastructure.org/projects/10084)
[](https://securityscorecards.dev/viewer/?uri=github.com/leplusorg/randalf)
[](https://pypi.python.org/pypi/randalf)
## Requirements
Requires Python 3.8 or later.
## Installation
### pip
Randalf is available on the Python Package Index (PyPI). You can
install it using the following command:
```shell
pip install randalf
```
### pipx
Randalf is also available via pipx:
```shell
pipx install 'git+https://github.com/leplusorg/randalf.git'
```
### Docker
See [docker-randalf](https://github.com/leplusorg/docker-randalf) for details.
## Usage
You need to invoke a 20-character alphanumeric spell:
```shell
randalf -l 20 -r 'a-zA-Z0-9'
```
Or you want to use any printable ASCII characters:
```shell
randalf -l 20 -r '^\x00-\x1f'
```
Maybe what you need is a 16-character hexadecimal string with
uppercase letters incantation:
```shell
randalf -l 16 -r '0-9A-F'
```
Or you are just bored and want to roll a dice:
```shell
randalf -l 1 -r '0-6'
```
Generate a 4-digit PIN? Easy:
```shell
randalf -l 4 -r '0-9'
```
A version 4 UUID?
```shell
s="$(randalf -l 32 -r '0-9a-f')"; printf "%s-%s-%s-%s-%s\n" "${s:0:8}" "${s:8:4}" "${s:12:4}" "${s:16:4}" "${s:20:12}"
```
Some random email address:
```shell
s="$(randalf -l 24 -r 'a-z')"; printf "%s.%s@%s.com\n" "${s:0:8}" "${s:8:8}" "${s:16:8}"
```
Or rather a random US phone number:
```shell
s="$(randalf -l 10 -r '0-9')"; printf "(%s) %s-%s\n" "${s:0:3}" "${s:3:3}" "${s:6:4}"
```
You get the idea...
## Implementation details
Repeat characters in the input ranges or alphabet are ignored.
The supported ranges are the same as inside the
(`[]`)[https://docs.python.org/3/library/re.html#index-10] of a python
regular expression. For a litteral `-`, `]`, '^' or '\', you can
escape then respectively as `\-`, `\]`, '\^' or '\\'. If the first
caracter of the ranges option is `^` it means the ranges defines the
prohibited characters instead of the desired ones. For non printable
characters, you can use notations like `\n`, or you can use the ASCII
value in octal (e.g. `\012`) or hexadecimal (e.g. `\xa0`). You can
also use the character classes like `\w`, `\W`, `\d`, `\D`, `\s` and
`\S`.
See `randalf -h` for details.