Shell或者perl进行随机分组的问题

1个回答

  • #!/usr/bin/perl

    #rand2.pl

    #Shell或者perl进行随机分组

    @file=`cat $ARGV[0]`;

    for (@file){

    chomp;

    ($r[$i][0],$r[$i][1],$r[$i][2])=(split)[0,1,2];

    $i++;

    }

    until (@all==1000){

    $check='';

    for(0..$#file){

    ($a[$_][0],$a[$_][1],$a[$_][2])=

    ($r[$_][0],

    int rand(($r[$_][1])*(3/5-2/5)+1)+ int($r[$_][1]*2/5),

    int rand(($r[$_][2])*(3/5-2/5)+1)+ int($r[$_][2]*2/5));

    ($b[$_][0],$b[$_][1],$b[$_][2])=

    ($r[$_][0],$r[$_][1]-$a[$_][1],$r[$_][2]-$a[$_][2]);

    $check.=$a[$_][1].$a[$_][2];

    }

    next if $check~~@all;

    push @all,$check;

    $n=@all;

    print "n=$n=n";

    print ":a".$n."n";

    print "$a[$_][0] $a[$_][1] $a[$_][2]n" for 0..$#file;

    print ":b".$n."n";

    print "$b[$_][0] $b[$_][1] $b[$_][2]n" for 0..$#file;

    }

    ------------------------------------------

    perl rand2.pl yourfile

    结果

    ..

    .

    =999=

    :a999

    1 6 8

    2 5 12

    3 6 12

    :b999

    1 4 8

    2 7 8

    3 9 10

    =1000=

    :a1000

    1 6 9

    2 5 11

    3 6 10

    :b1000

    1 4 7

    2 7 9

    3 9 12