This repository has been archived on 2021-05-26. You can view files and clone it, but cannot push or open issues or pull requests.
OS/pintos-env/pintos/tests/lib.pm

20 lines
361 B
Perl
Raw Normal View History

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;