- Home /
This post has been wikified, any user with enough reputation can edit it.
random object cube use algorithm fisher yates shuffle
guys I want ask about randomization with using algorithm Fisher Yates Shuffle in C#.
I have 8 cubes, I want to do randomization with Algorithm Fisher Yates Shuffle each game begins , so that the position of the cube can be changed.
Can you help me how the source code for the language C#?
sorry if my english is bad.
Comment
Your english is okay. But your question is bad. No one is going to help write code for you. Ins$$anonymous$$d, publish what you have written, and explain what goes wrong.
here my script mr.Graham Dunnett:
using UnityEngine; using System.Collections; using System.Collections.Generic;
public class AlgoritmaFYS : $$anonymous$$onoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
string[] array = {
gameObject.name="cube1",
gameObject.name="cube2",
gameObject.name="cube3",
gameObject.name="cube4",
gameObject.name="cube5",
gameObject.name="cube6",
gameObject.name="cube7",
gameObject.name="cube8"
};
ShuffleArray(array);
}
public static void ShuffleArray<T>(T[] array) {
for (int i = array.Length - 1; i > 0; i--) {
int r = Random.Range(0, i);
T tmp = array[i];
array[i] = array[r];
array[r] = tmp;
}
}
}
this is the true code or false, because it's not work.