viewing paste topic/14817- shuffle and sort | Athena

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
function    script  array_shuffle   {
    .@size = getarraysize(getarg(0));
    for (.@i = .@size - 1; .@i >= 1; --.@i)
        swap(getelementofarray(getarg(0), rand(0, .@i)), getelementofarray(getarg(0), .@i));
    return true;
}
 
function    script  array_sort  {
    .@total = .@size = getarraysize( getarg(0) );
    copyarray .@arr, getarg(0), .@size;
    for ( .@i = 0; .@i < .@size; ++.@i )
        ++.@tmp[.@arr[.@i]];
    for ( ; .@size; --.@size ) {
        .@index = getarraysize(.@tmp) -1;
        .@output[.@size-1] = .@index;
        --.@tmp[.@index];
    }
    copyarray getarg(0), .@output, .@total;
    return;
}
 
function    script  printdispbottom {
    .@size = getarraysize( getarg(1) );
    for ( .@i = 0; .@i < .@size; ++.@i )
        .@print$ += getelementofarray( getarg(1), .@i )+",";
    dispbottom getarg(0) +" = "+ .@print$;
    return;
}
 
poring_w01,105,100,5    script  222 1_F_MARIA,{
    dispbottom " ==== "+ strnpcinfo(NPC_NAME) +" ===";
    setarray .@a, 0,1,2,3,4,5,6,7,8,9;
//      1,2,5,6,3,8,9,4,6,3,5,6,8,3,5;
    printdispbottom "original", .@a;
    array_shuffle .@a;
    printdispbottom " shuffle", .@a;
    array_sort .@a;
    printdispbottom "     sort", .@a;
    end;
}
Viewed 937 times, submitted by AnnieRuru.