Hello,
I am trying to sort some randomly generated player turns and then correctly assign them and also make sure there are no repetitions. I will show what I mean below:

I have randomly generated 4 numbers for players from the code below, my goal is that the player with the highest number gets to go first, the player with the second highest number goes next, etc. etc.

Code:
function turns()
{
	random_seed(0);
	player1_turn = integer(random(100));
	turn_array[0] = player1_turn;
	
	player2_turn = integer(random(100));
	turn_array[1] = player2_turn;
		
	player3_turn = integer(random(100));
	turn_array[2] = player3_turn;
		
	player4_turn = integer(random(100));
	turn_array[3] = player4_turn;
}




Next I have sorted the data with a reverse bubble sort like this:
Code:
////////simple bubble sort///////
var i;
var j;
var hold;
	
for (i=0; i<7; i++) //passes
{
 for (j=0; j<7; j++) //one pass
 {
	if (turn_array[j] < turn_array[j+1]) //one comparison 
	{
	 hold = turn_array[j];   //one swap
	 turn_array[j] = turn_array[j+1];
	 turn_array[j+1] = hold;
				
	}
  }
 }



All of this code works successfully, my 4 generated numbers are sorted from highest to lowest. But I still have two problems:

#1 PROBLEM is that I need to assign the turn order to the respective players

#2 PROBLEM I don't know how to deal with situations where I have two of the same numbers like if 2 "45"'s show up.


So I was hoping there was a way to fix one or both of these problems in an efficient manner, but any help or directions at all would be excellent.

Let me know if I didn't describe the problem clearly. crazy

Thanks