I guess something like this will work.
Actually, I thought of rates/total_rates*100 to get the percentage, but the emulator failed to calculate decimals. I know there are other ways to get the decimals, but will not be as efficient as the below one? O_O
setarray .@array, <item_id>,<rates>{...};
for ( set .@i, 0; .@i < getarraysize(.@array); set .@i, .@i + 2 )
.@t, .@t + .@array[.@i+1];
if ( .@t <= 0 || .@t >= 2147483647 ) // I think you won't go that high...
{
debugmes "O_O You really go that high...";
end;
}
set .@rnd, rand(1,.@t);
for ( set .@i, 0; .@i < getarraysize(.@array); set .@i, .@i + 2 )
{
.@sr, .@sr + .@array[.@i+1];
if ( .@sr >= .@rnd ) { //GetItem }
}