how to mix playing cards ? Help

I have 36 cards that I would mix randomly when I click a button, and then they place correctly on the screen (on line).

View image example with 4 cards.

I think I can use an array to do this kind of manipulation, but I am new to programming, so if someone has an idea for this kind of code …

thank you

My real problem is when I enter this scene, I would put a script on the camera (I think) and I want my card is placed in positions that I want.
I do not know how to handle my card via my script.

Can anyone help me?

Thank you

Hi,
Yes, arrays are the best way to handle the randomisation of the cards

The standard way to do this is to start with 2 arrays

Array 1: [1,2,3,4,5…] and Array 2: [ ]

Randomly pick a number (ie a position in the array) from Array 1, remove it (ie that position) from Array 1, and Add it to Array2.

Array 1 will get smaller with each iteration, so your random range needs to change accordingly.

When Array1 is empty, the job is done.

Regards,

PW

You can also do it with a single array. Go through each index of the array in a loop and swap the element at that index with a randomly-chosen element (use Random.Range to find a random index).

Thank you to every two to this information.

This is the shuffle array script that I originally made for Actionscript… the concept should work in Javascript too.

yourArray = new Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m");

//This is the array shuffle function.
function shuffleArray(arrayName) {
	for (i = 0; i < arrayName.length; i++) {
		//reverse the array every time to add more even shuffling; not necessary, but helpful
		arrayName.reverse();
		//remove a single item in the array, and push it to the end of the array
		arrayName.push(arrayName.splice(random(arrayName.length), 1));
		//see the new shuffled array in the trace window
	}
}

//Call the function, and put the name of your array inside
shuffleArray(yourArray)

Sorry - I should have posted my code too (see attachment).

191283–6775–$shufflecards_194.cs (766 Bytes)