1#!perl 2 3package Math::BigInt::Lib::TestUtil; 4 5use strict; 6use warnings; 7 8use Exporter; 9 10our @ISA = qw< Exporter >; 11our @EXPORT_OK = qw< randstr >; 12 13# randstr NUM, BASE 14# 15# Generate a string representing a NUM digit number in base BASE. 16 17sub randstr { 18 die "randstr: wrong number of input arguments\n" 19 unless @_ == 2; 20 21 my $n = shift; 22 my $b = shift; 23 24 die "randstr: first input argument must be >= 0" 25 unless $n >= 0; 26 die "randstr: second input argument must be in the range 2 .. 36\n" 27 unless 2 <= $b && $b <= 36; 28 29 return '' if $n == 0; 30 31 my @dig = (0 .. 9, 'a' .. 'z'); 32 33 my $str = $dig[ 1 + int rand ($b - 1) ]; 34 $str .= $dig[ int rand $b ] for 2 .. $n; 35 36 return $str; 37} 38 391; 40