aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/lib.pm
blob: bc37ae5245f043452af7718d1c4b0336a302801f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use strict;
use warnings;

use tests::random;

sub shuffle {
    my ($in, $cnt, $sz) = @_;
    $cnt * $sz == length $in or die;
    my (@a) = 0...$cnt - 1;
    for my $i (0...$cnt - 1) {
	my ($j) = $i + random_ulong () % ($cnt - $i);
	@a[$i, $j] = @a[$j, $i];
    }
    my ($out) = "";
    $out .= substr ($in, $_ * $sz, $sz) foreach @a;
    return $out;
}

1;