How to make a random string from array in C#?
Hi there, guys! I'm making a rubik's cube game, and there is a timer in it. And it needs to have a random scramble which is in a array (it already has, but it's not a good one). Look:
public Button botao;
public Sprite imagemStart;
public List<string> Scramble;
public Text textScramble;
public float mil;
public float sec;
public int min;
public void ChangeBool(){
BtnBoolean = !BtnBoolean;
sec = 0;
mil = 0;
min = 0;
textScramble.text = "";
if(!BtnBoolean){
int i = 0;
while(i < 12){
textScramble.text += Scramble[UnityEngine.Random.Range(0, Scramble.Count - 1)].ToString();
i ++;
}
botao.image.overrideSprite = imagemStart;
}
}
It works, but it has some issues like this:
It must not repeat the previous algorithm. So, my question is: How can I make a random algorithm (R or R' or R2 or L or L' or L2, etc) wihtout repeating the previous movement (letter)? Sorry for my bad english. Please, can someone help me?
Answer by Im-Brazilian · Nov 14, 2016 at 12:41 AM
I thought in some like:
while(i < 12){
if(Scramble != previousLetter || Scramble != previousPreviousLetter){
textScramble.text += Scramble[UnityEngine.Random.Range(0, Scramble.Count - 1)].ToString();
i ++;
}
}
Your answer
Follow this Question
Related Questions
C# Random String from List 2 Answers
C# Adding random values to array 1 Answer
Pick a random string from a string array C# 1 Answer
trying to get an Array string to read an Int 0 Answers
Storing input to array 1 Answer