Bytes::Random::Secure: Most of this module deals with returning random bytes, but there is one function that returns a random string by picking octets at random from a user-supplied "bag" string. It works with Unicode strings as well (it turned out to be a simple thing to implement, despite the module's "Bytes" name).
use strict;
use warnings;
use Bytes::Random::Secure qw( random_string_from );
use feature qw/unicode_strings/;
binmode STDOUT, ':utf8';
my $string = random_string_from(
join( '', map { chr($_ ) } 0 .. 0x10FFFF ), # Generate a "bag" st
+ring.
16384 # Return a string of 16384 octets from the "bag".
);
print $string, "\n";
print length($string), "\n";
Not terribly efficient/, but if you precompute the "bag" string it's efficient enough for most purposes.
Care was taken to ensure that there's no modulo bias, which would be likely to turn up in simplisitic solutions. The random generator is the ISAAC algorithm. And the generator is seeded using the strongest source available on the target platform. Performance can be improved by making sure that Math::Random::ISAAC::XS is installed on the target system; the ISAAC generator will use it if it's available. On Windows systems there's one additional dependency to assure a strong seed. You'll have to read the POD if that's an issue.