actionscript 3 - Array shuffle function not touching last element -
actionscript 3 - Array shuffle function not touching last element -
i using function shuffle 4 element array. shuffles first 3 elements well, shuffling them randomly, lastly element shuffled around other three.
public function shufflearray(obja:object, objb:object):int{ homecoming math.round(math.random() * 2) - 1; }
there's nil wrong it. that's random. mentioned, algorithm used math.random()
makes difference , don't believe as3 algorithm good.
for testing purposes, ran few times in js , saw similar things, specific index same quite few times in row. results showing 5-10 times in row, 1 of indexes same. in few tests, saw exact same result appear 11 times in row. running higher maxvalue
(i tried 15) resulted in much more random outcome, though still had same problems. interestingly, bumping iterations seemed break pattern. noticed became more random got higher in tries (i tried 10k).
var maxvalue = 4, iterations = 100, = []; (var = 1; <= maxvalue; i++) { a.push(i); } function shuffle(a, b) { homecoming math.round(math.random() * 2) - 1; } (var = 0; < iterations; i++) { console.log(a.sort(shuffle)); }
http://jsfiddle.net/ka2tf/1/
i did test same code in flash (with minor alterations as3, obviously) , saw similar results (to expected; believe flash , js utilize similar algorithms, if not same one). there's 24 different combinations 4 item array can sorted. you're bound repetition.
actionscript-3 flash air
Comments
Post a Comment