NAME
cfbase32-rand - Generate one or more Crockford Base 32 numbers
VERSION
This document describes version 0.004 of cfbase32-rand (from Perl distribution App-CrockfordBase32Utils), released on 2026-01-20.
SYNOPSIS
cfbase32-rand --help (or -h, -?)
cfbase32-rand --version (or -v)
cfbase32-rand [--debug|--log-level=level|--quiet|--trace|--verbose] [--fill-char-template=str|-f=str] [--format=name|--json] [--len=int|-l=int] [--max-base32=str] [--max-int=int] [--max-len=int] [--min-base32=str] [--min-int=int] [--min-len=int] [--(no)naked-res] [--num=uint|-n=uint] [--page-result[=program]|--view-result[=program]] [--prev-file=filename|-p=filename] [--unique|-u|--no-unique|--nounique] [--zero-prefix|--no-zero-prefix|--nozero-prefix]
See examples in the "EXAMPLES" section.
DESCRIPTION
This routine uses Math::Random::Secure for cryptographically secure random number generator.
OPTIONS
* marks required options.
Main options
Logging options
- --debug
-
Shortcut for --log-level=debug.
- --log-level=s
-
Set log level.
By default, these log levels are available (in order of increasing level of importance, from least important to most):
trace,debug,info,warn/warning,error,fatal. By default, the level is usually set towarn, which means that log statements with levelinfoand less important levels will not be shown. To increase verbosity, chooseinfo,debug, ortrace.For more details on log level and logging, as well as how new logging levels can be defined or existing ones modified, see Log::ger.
- --quiet
-
Shortcut for --log-level=error.
- --trace
-
Shortcut for --log-level=trace.
- --verbose
-
Shortcut for --log-level=info.
Output options
- --fill-char-template=s, -f
-
Provide a template for formatting number, e.g. "###-###-###".
See String::FillCharTemplate for more details.
- --format=s
-
Choose output format, e.g. json, text.
Default value:
undefOutput can be displayed in multiple formats, and a suitable default format is chosen depending on the application and/or whether output destination is interactive terminal (i.e. whether output is piped). This option specifically chooses an output format.
- --json
-
Set output format to json.
- --naked-res
-
When outputing as JSON, strip result envelope.
Default value:
0By default, when outputing as JSON, the full enveloped result is returned, e.g.:
[200,"OK",[1,2,3],{"func.extra"=>4}]The reason is so you can get the status (1st element), status message (2nd element) as well as result metadata/extra result (4th element) instead of just the result (3rd element). However, sometimes you want just the result, e.g. when you want to pipe the result for more post-processing. In this case you can use
--naked-resso you just get:[1,2,3] - --page-result
-
Filter output through a pager.
This option will pipe the output to a specified pager program. If pager program is not specified, a suitable default e.g.
lessis chosen. - --prev-file=s, -p
-
Load list of previous numbers from the specified file.
The file will be read per-line. Empty lines and lines starting with "#" will be skipped. Non-digits will be removed first. Lowercase will be converted to uppercase. I L will be normalized to 1, O will be normalized to 0.
- --unique, -u
-
Whether to avoid generating previously generated numbers.
- --view-result
-
View output using a viewer.
This option will first save the output to a temporary file, then open a viewer program to view the temporary file. If a viewer program is not chosen, a suitable default, e.g. the browser, is chosen.
Quantity options
Range options
- --len=s, -l
-
Specify how many number of digits to generate for a number.
Note that the first digit can still be 0 unless zero_prefix is set to false.
- --max-base32=s
-
(No description)
- --max-int=s
-
(No description)
- --max-len=s
-
Specify how many maximum number of digits to generate.
Note that the first digit can still be 0 unless zero_prefix is set to false.
- --min-base32=s
-
(No description)
- --min-int=s
-
(No description)
- --min-len=s
-
Specify how many minimum number of digits to generate.
Note that the first digit can still be 0 unless zero_prefix is set to false.
Other options
COMPLETION
This script has shell tab completion capability with support for several shells.
bash
To activate bash completion for this script, put:
complete -C cfbase32-rand cfbase32-rand
in your bash startup (e.g. ~/.bashrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is recommended, however, that you install modules using cpanm-shcompgen which can activate shell completion for scripts immediately.
tcsh
To activate tcsh completion for this script, put:
complete cfbase32-rand 'p/*/`cfbase32-rand`/'
in your tcsh startup (e.g. ~/.tcshrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is also recommended to install shcompgen (see above).
other shells
For fish and zsh, install shcompgen as described above.
EXAMPLES
Generate 35 random numbers from 12 digits each, first digit(s) can be 0
% cfbase32-rand --len 12 -n35
6NWN5JWAW5GX
9ZY8XQT3PNRE
8F78DZGAPY8G
DNJ6XBP14YWS
MRZE4Z6SK2FT
CHXE5NDK7V7E
0DFS3H88NG28
RY4RWG82F5HN
Q38RM937EW18
T25VXN8ZCHN9
W9R98R1GZGNX
8JFNPPNQZEKN
GM7DN3Z7R6N5
4QZ5QV0ZCNXC
P64BSA9NG7QP
31R0EBW56ZH6
64CCPQYGXV1Q
4A1BMWVC4X6X
R78H733A2S00
B8FPFY8S49Y3
M3KSB9R2VPS4
YG1HFHMCDNTE
GAJDQNJT4SMP
KF2SZ9KMXS5N
19JGT1QBY8VX
M8TT4M9J1E99
5FF654AGFTWE
R16TGSW7A2D1
3Y1CF0SA1Q1C
KGT5SFKBD73Q
GSS4CSRRANE2
WCA7EV3CZZH0
2J5CE7YXVWE1
TCVATAF2XECW
ERVYVWTWEP20
Generate 35 random numbers from 12 digits each, first digit(s) CANNOT be 0
% cfbase32-rand --len 12 -n35 --nozero-prefix
6P9YBNX7XJMG
5G18PKVK1THT
FDRTYBSZB97D
7JZR74ZH747Q
GD5XJNABSPGH
957PANEPFYRG
QE20019RCRCM
Y89704S54MYZ
T58DY8VTVEZ6
PHNF6HV9Y8H8
144W43C2CD7Z
MY0GQZSTT9R4
TTQA35XKGAAN
4593NYGWCED5
HA70Q0D39XMD
R6D4J032V2HZ
A71X7PKY56TB
H7TGVK5BD5NR
V9ED2V9NPXSA
2XMH7T54VTE5
E5W92CRXZSW0
C98Q93ET7AC8
Q1C2JEDHM8G0
FT4HB3SQNGJT
7VY993V311C0
FBKTDTE9HT0H
SZQ7617MVM43
5JRD5VMQBYNZ
1R73RSHCCGQ5
TVD6DYVV2PZT
KR1233YJYCXE
KAYW20TZXM46
FSYB8HBYQCSY
HC2FW4357PPQ
EHC5D05MW62G
Generate a formatted random code
% cfbase32-rand -f '###-###-###' -l9
1QN-EMH-80S
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/App-CrockfordBase32Utils.
SOURCE
Source repository is at https://github.com/perlancar/perl-App-CrockfordBase32Utils.
AUTHOR
perlancar <perlancar@cpan.org>
CONTRIBUTING
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-CrockfordBase32Utils
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.