Basically, you should be able to do
#!/usr/bin/env perl use strict; use warnings; for (1 .. 10) { printf "%08X\n", rand(0xffffffff); }
However, you can find out that, at least on some systems with some perl
(if not all) - the range of rand
limited to 32,768 values .
You can also examine the source code of String :: Random to learn how to create random strings that satisfy other conditions.
However, my caution against using native rand
on a Windows system is still worth it. See Math :: Random :: MT for high-quality RNG.
#!/usr/bin/env perl use strict; use warnings; my @set = ('0' ..'9', 'A' .. 'F'); my $str = join '' => map $set[rand @set], 1 .. 8; print "$str\n";
PS: The problem with Perl rand on Windows was fixed in 5.20 :
This meant that the quality of perl random numbers would vary from platform to platform, from 15 bits of rand () on Windows to 48 bits on POSIX platforms like Linux with drand48 ().
Perl now uses its own internal implementation of drand48 () on all platforms. This does not do cryptographic security perl rand. [perl # 115928]
source share