Is there off-the-shelf open source software for generating serial numbers of user-definable number bases?

212 Views Asked by At

Is there off-the-shelf open source software for generating serial numbers of user-definable number bases?

Preferably in Perl, or similar scripting language.

1

There are 1 best solutions below

2
On BEST ANSWER

Take a look at Integer::Tiny. It allows you to specify an arbitrarily-sized string of single-character "digits", then converts integers into that set. Give it a string of length n and the number is effectively converted into base n (although it won't look like a normal base n representation unless that string orders the digits normally, of course).

Edit: Here's the one-liner base-10 solution from Sorpigal's comment redone in base-3:

perl -MInteger::Tiny -e 'my $it = Integer::Tiny->new("012"); printf "%0".$ARGV[0]."d\n", $it->encrypt($_) for (shift..shift);' 1 10 5