File: bias.t

package info (click to toggle)
libcrypt-urandom-token-perl 0.005-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 120 kB
  • sloc: perl: 53; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 509 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use strict;
use utf8;
use Test::More;

use_ok("Crypt::URandom::Token" => qw(urandom_token));

my $len       = 2_000_000;
my @alphabet  = ("A" .. "Z", "a" .. "z", "0" .. "9");
my $tolerance = 0.05;

my %values;
foreach my $char (split "", urandom_token($len, \@alphabet)) {
  $values{$char}++;
}

my $avg = $len / @alphabet;
foreach my $char (@alphabet) {
  my $cnt  = $values{$char} || 0;
  my $diff = abs($avg - $cnt);
  cmp_ok($diff, "<", $tolerance * $avg, "$char is within tolerance");
}

done_testing();