Originally Posted By: Clemens
I wrote a function, which fill an array with numbers in a random order:

Code:
function array_randomized_order(var* array, length, start) {
	random_seed(0);
	i=0;
	while (i<length) {
		array[i] = integer(random(length))+start;
		// check if double?
		for (j=0; j<i; j++) {
			if (array[i] == array[j]) {	// if it is:
				i--;			// jump back..
				continue;		// ..and repeat
			}
		}	
		i++;
	}
}
var order[3];
array_randomized_order(order, 3, 1);
	// result is either 1,2,3 or 1,3,2 or 2,1,3 or 2,3,1  or 3,1,2 or 3,2,1



This function works. My only question is, does it really works?
Can you find any systematic errors? Is it surely absolute random, every time I use it? -> toward unlimited calls every order combination would have been appeared the same times?!?
Any suggestions or critics?

Thanks for statements,
Clemens

The way you're doing it there is greater than O^2, if you have a number being repeatedly chosen, you'll be causing problems later on when randomising larger length arrays.

Here's a snippet I wrote a while ago, I've added comments so hopefully you'll see what's happening
Code:
void random_order(int* array, int max, int start){
	
	random_seed(0);
	
	int i, j, pos, temp[255]; //change 4 if max greater
	
	//set up possible numbers
	for(i = 0; i < max; i++){
		
		if(i < max){
			temp[i] = i + start;
		}else{
			break;
		}
	}
	
	//set array with numbers
	for(i = max; i > 0; i--){
		
		pos = integer(random[i]); //choose number from 0 to max
		array[i-1] = temp[pos]; //set in array
		
		//remove number from possibles
		for(j = pos; j < i; j++){
			temp[j] = temp[j+1];
		}
	}
}

hope this helps