// ============== my first shuffle ========================
prontera,148,185,5 script my 1st shuffle 1_F_MARIA,{
dispbottom "=== "+ strnpcinfo(0) +" ===";
.@loop = 600;
freeloop true;
for ( .@l = 0; .@l < .@loop; ++.@l ) {
callfunc "rand__", 3, .@output;
for ( .@i = 0; .@i < 3; ++.@i )
.@tmp$[.@i] = .@output[.@i] +"";
.@print$ = implode( .@tmp$, "," );
setarray .@resultset$, "0,1,2","0,2,1","1,0,2","1,2,0","2,1,0","2,0,1";
for ( .@i = 0; .@i < 6; ++.@i ) {
if ( .@print$ == .@resultset$[.@i] ) {
.@resultset[.@i]++;
break;
}
}
}
for ( .@i = 0; .@i < 6; ++.@i ) {
dispbottom "result set "+( .@i +1 )+" '"+ .@resultset$[.@i] +"' has "+ .@resultset[.@i] +" times.";
.@total += .@resultset[.@i];
}
dispbottom "total = "+ .@total;
end;
}
function script rand__ {
deletearray getarg(1);
.@limit = getarg(0);
if ( .@limit <= 0 )
return 0;
for ( .@i = 0; .@i < .@limit; ++.@i )
.@array_[.@i] = .@i;
.@arraysize = .@limit;
for ( .@i = 0; .@i < .@limit; ++.@i ) {
.@rand = rand(.@arraysize);
set getelementofarray( getarg(1), .@i ), .@array_[.@rand];
copyarray .@array_[.@rand], .@array_[.@rand+1], .@arraysize;
--.@arraysize;
}
return .@limit;
}
// ===== my 2nd shuffle =================== NO GOOD ....
prontera,151,185,5 script my 2nd shuffle 1_F_MARIA,{
dispbottom "=== "+ strnpcinfo(0) +" ===";
.@loop = 600;
freeloop true;
for ( .@l = 0; .@l < .@loop; ++.@l ) {
callfunc "rand__2", 3, .@output;
for ( .@i = 0; .@i < 3; ++.@i )
.@tmp$[.@i] = .@output[.@i] +"";
.@print$ = implode( .@tmp$, "," );
// dispbottom .@print$;
setarray .@resultset$, "0,1,2","0,2,1","1,0,2","1,2,0","2,1,0","2,0,1";
for ( .@i = 0; .@i < 6; ++.@i ) {
if ( .@print$ == .@resultset$[.@i] ) {
.@resultset[.@i]++;
break;
}
}
}
for ( .@i = 0; .@i < 6; ++.@i ) {
dispbottom "result set "+( .@i +1 )+" '"+ .@resultset$[.@i] +"' has "+ .@resultset[.@i] +" times.";
.@total += .@resultset[.@i];
}
dispbottom "total = "+ .@total;
end;
}
function script rand__2 {
deletearray getarg(1);
.@limit = getarg(0);
.@index = getarg(2, 0);
if ( .@limit <= 0 ) return 0;
if ( .@index == 0 ) .@index = .@limit;
.@i = 0;
while ( .@i < .@limit ) {
.@array_[.@i] = .@i;
++.@i;
}
.@i = 0;
while ( .@i < .@limit ) {
.@rand = .@i + ( rand(2000000000) % ( .@limit - .@i ) );
.@var = .@array_[.@rand];
.@array_[.@rand] = .@array[.@i];
.@array_[.@i] = .@var;
set getelementofarray( getarg(1), .@i ), .@var;
++.@i;
}
return .@index;
}
// ============== This is the one I got it from ==========================
prontera,154,185,5 script eathena keyworld shuffle 1_F_MARIA,{
dispbottom "=== "+ strnpcinfo(0) +" ===";
.@loop = 600;
freeloop true;
for ( .@l = 0; .@l < .@loop; ++.@l ) {
callfunc "eathena_keyworld_shuffle", 3, .@output;
for ( .@i = 0; .@i < 3; ++.@i )
.@tmp$[.@i] = .@output[.@i] +"";
.@print$ = implode( .@tmp$, "," );
// dispbottom .@print$;
setarray .@resultset$, "0,1,2","0,2,1","1,0,2","1,2,0","2,1,0","2,0,1";
for ( .@i = 0; .@i < 6; ++.@i ) {
if ( .@print$ == .@resultset$[.@i] ) {
.@resultset[.@i]++;
break;
}
}
}
for ( .@i = 0; .@i < 6; ++.@i ) {
dispbottom "result set "+( .@i +1 )+" '"+ .@resultset$[.@i] +"' has "+ .@resultset[.@i] +" times.";
.@total += .@resultset[.@i];
}
dispbottom "total = "+ .@total;
end;
}
function script eathena_keyworld_shuffle {
set .@range, getarg(0);
set .@count, getarg(2,0);
set .@count,
( .@count == 0 || .@count > .@range )? .@range :
( .@count > 128 )? 128 : .@count;
while ( .@i < .@count ) {
set .@r, rand( .@i, .@range -1 );
set .@save, .@r;
if ( !.@tmp[.@i] ) {
set .@r, ( .@tmp[.@r] )? getd( getarg(1) +"["+ .@r +"]" ) : .@r;
set getelementofarray( getarg(1), .@i ), .@r;
set getelementofarray( getarg(1), .@save ), .@i;
set .@tmp[.@save], 1;
}
set .@i, .@i+1;
}
return .@count;
}
// ======== write a new one with fisher yates shuffle - modern method ============
prontera,157,185,5 script modern fisher yates 1_F_MARIA,{
dispbottom "=== "+ strnpcinfo(0) +" ===";
.@loop = 600;
freeloop true;
for ( .@l = 0; .@l < .@loop; ++.@l ) {
callfunc "modern_fisher_yates", 3, .@output;
for ( .@i = 0; .@i < 3; ++.@i )
.@tmp$[.@i] = .@output[.@i] +"";
.@print$ = implode( .@tmp$, "," );
setarray .@resultset$, "0,1,2","0,2,1","1,0,2","1,2,0","2,1,0","2,0,1";
for ( .@i = 0; .@i < 6; ++.@i ) {
if ( .@print$ == .@resultset$[.@i] ) {
.@resultset[.@i]++;
break;
}
}
}
for ( .@i = 0; .@i < 6; ++.@i ) {
dispbottom "result set "+( .@i +1 )+" '"+ .@resultset$[.@i] +"' has "+ .@resultset[.@i] +" times.";
.@total += .@resultset[.@i];
}
dispbottom "total = "+ .@total;
end;
}
function script modern_fisher_yates {
deletearray getarg(1);
.@size = .@tmpsize = getarg(0);
if ( .@size <= 0 )
return 0;
for ( .@i = 0; .@i < .@size; ++.@i )
.@array_[.@i] = .@i;
for ( .@i = 0; .@i < .@size; ++.@i ) {
.@rand = rand(.@tmpsize);
set getelementofarray( getarg(1), .@i ), .@array_[.@rand];
deletearray .@array_[.@rand], 1;
--.@tmpsize;
}
return .@size;
}
// =================== Haru's shuffle ===========================================
prontera,160,185,5 script Haru shuffle 1_F_MARIA,{
dispbottom "=== "+ strnpcinfo(0) +" ===";
.@loop = 600;
freeloop true;
for ( .@l = 0; .@l < .@loop; ++.@l ) {
callfunc "Haru_shuffle", 3, .@output;
for ( .@i = 0; .@i < 3; ++.@i )
.@tmp$[.@i] = .@output[.@i] +"";
.@print$ = implode( .@tmp$, "," );
setarray .@resultset$, "0,1,2","0,2,1","1,0,2","1,2,0","2,1,0","2,0,1";
for ( .@i = 0; .@i < 6; ++.@i ) {
if ( .@print$ == .@resultset$[.@i] ) {
.@resultset[.@i]++;
break;
}
}
}
for ( .@i = 0; .@i < 6; ++.@i ) {
dispbottom "result set "+( .@i +1 )+" '"+ .@resultset$[.@i] +"' has "+ .@resultset[.@i] +" times.";
.@total += .@resultset[.@i];
}
dispbottom "total = "+ .@total;
end;
}
function script Haru_shuffle {
deletearray getarg(1);
.@count = getarg(0);
for ( .@i = 0; .@i < .@count; ++.@i ) {
do {
.@pick = rand( .@count );
} while ( .@flags[.@pick] );
set getelementofarray( getarg(1), .@i ), .@pick;
.@flags[.@pick] = 1;
}
return .@size;
}
// ================= keyworld infinite loop shuffle =============================
prontera,160,182,5 script keyworld infinite shuffle 1_F_MARIA,{
dispbottom "=== "+ strnpcinfo(0) +" ===";
.@loop = 600;
freeloop true;
for ( .@l = 0; .@l < .@loop; ++.@l ) {
callfunc "keyworld_infinite_shuffle", 3, .@output;
for ( .@i = 0; .@i < 3; ++.@i )
.@tmp$[.@i] = .@output[.@i] +"";
.@print$ = implode( .@tmp$, "," );
setarray .@resultset$, "0,1,2","0,2,1","1,0,2","1,2,0","2,1,0","2,0,1";
for ( .@i = 0; .@i < 6; ++.@i ) {
if ( .@print$ == .@resultset$[.@i] ) {
.@resultset[.@i]++;
break;
}
}
}
for ( .@i = 0; .@i < 6; ++.@i ) {
dispbottom "result set "+( .@i +1 )+" '"+ .@resultset$[.@i] +"' has "+ .@resultset[.@i] +" times.";
.@total += .@resultset[.@i];
}
dispbottom "total = "+ .@total;
end;
}
function script keyworld_inf_shuffle {
deletearray getarg(1);
.@count = getarg(0);
.@tmp$ = "|";
for ( .@i = 0; .@i < .@count; ++.@i ) {
while ( compare( .@tmp$, "|" +( .@pick = rand( .@count ) )+ "|" ) );
set getelementofarray( getarg(1), .@i ), .@pick;
.@tmp$ += .@pick +"|";
}
return .@size;
}