NAME

cfbase32-rand - Generate one or more Crockford Base 32 numbers

VERSION

This document describes version 0.005 of cfbase32-rand (from Perl distribution App-CrockfordBase32Utils), released on 2026-01-28.

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

--no-zero-prefix

(No description)

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 to warn, which means that log statements with level info and less important levels will not be shown. To increase verbosity, choose info, debug, or trace.

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:

undef

Output 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:

0

By 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-res so 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. less is 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

--num=s, -n

Specify how many numbers to generate.

Default value:

1

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

--help, -h, -?

Display help message and exit.

--version, -v

Display program's version and exit.

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
YTF811XA8DA6
ER14YKN6R4D4
2GV9SYTWB3JC
07BDE766KY4W
JZEGR7VXQMPX
4H3V1DMDJ4CN
J16ATVFQFEE8
X0MPGYH1SVPV
JQCMRZAPRK98
891V2M3XQ9K1
7FAPVX94KC46
8DMMJMG70TE6
QHE9XWWX5Q8F
4GQK8JY3PHVS
4KBEWVB9RSVF
27K2SGH6ZP8Q
DV9H0WMGKBH8
R786FJ4N9C12
9KCD67868QTV
SVED4AXQNYKN
G29GHD8X9E11
S0DWPMDEFS07
JKD6MFNMNGEZ
YSEA0HFQJFWP
JF27Q18GAVJ3
EY470KWTZC8N
KTJV3QYNZ0AD
RVWDFCMB411N
8AE72FNMQG29
ET0ADXCEV7YA
BWN8Z5XY0VVT
DRX2RHPN37H1
HRDFM7APZ13Q
KJ81QS12AD23
09033GCZD8J6

Generate 35 random numbers from 12 digits each, first digit(s) CANNOT be 0

% cfbase32-rand --len 12 -n35 --nozero-prefix
5R515AFS2MRV
WWR7V28GXS53
83P3KFRSAMPX
TFVCDJY40QYP
VXHDT98PTJK3
Y8KHD1B4JKDB
9GD0FQ0YKQZX
JA1QA1255RBV
DYACNXYF1F7J
TCW6ATEMHHY6
NDGFFA9SPH1T
BQ6ERH4G23A4
PG80TVEWHNFT
1K0BRFZFSFPA
EPH11XQWV5F9
FTZZEF1W83VE
Q7NFX3KB4JGZ
CGRZXXVKC3WT
5FN0YR3GKTR1
YXF8QAP21156
2YKZG6YQT1W7
RQFFMZEV64B3
846QVW7J1ESF
QH910E90DRZ1
HS125DA14J5H
2E41EZHWZ8V8
2H08APREPDCX
1M0KJVXATR2F
HDD69NP64KXB
R861F9YR3EKA
S226EHPSS79B
RNWMSXT1C1KJ
DV205SYX7T61
AJE9YWCZT4VV
7QETJDJHQ06S

Generate a formatted random code

% cfbase32-rand -f '###-###-###' -l9
DZ9-P9F-YKT

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.