At first: Thank you guys! Really good and helpful input!
@Joey: Of course, you are right, has to be
break for less loops! Did you mean with "arrays shuffling" the way like MrGuest did it??
@MrGuest: Great code snippet!! Thanks for sharing it! However I'm wondering about your
if(i < max){ [...] }else{break;} - cause that does the loop. And furthermore it has to be
random(i).
@both: Your calculation of the ressources the algorithms need sounds really interessting. You wrote "O(length)" or "(O^2)"- what exactly does that mean? Do you have some explanations or links about methods to see/read such programming information?
I made tests with both algorithms:
testarray1[4];
testarray2[4];
for (i=1; i<=2100; i++) {
array_randomized_order(testarray1, 4, 1);
random_order(testarray2, 4, 1);
Sum1 += testarray[0]; // could have check it as well with 1/2/3
Sum2 += testarray[0];
wait(-0.2);
Sum_counter += 1;
}
The results were:
1. test:
Sum1 = 5336
Sum2 = 5172
Sum_counter = 2100
2. test
Sum1 = 5244
Sum2 = 5244
Sum_counter = 2100
3. test
Sum1 = 5223
Sum2 = 5313
Sum_counter = 2100
2100*2.5 = 5250 => that's the ideal outcome
I didn't make a significance test - but looks like both algorithm have (same) absolute acceptable results!
At all I will use MrGuest's one, which is more flexible and probably faster.
Greetings,
Clemens