0
I’m finishing a project of Quiz Unity game in C#, let me try to explain what I need, I already ask the random questions, but I want the answers to be displayed at random as well. I have a list of 5 questions, each question has 4 alternatives, the questions are selected by an ID. today the code is so:
pergunta.text = perguntas[idPergunta];
respostaA.text = alternativa1[idPergunta];
respostaB.text = alternativa2[idPergunta];
respostaC.text = alternativa3[idPergunta];
respostaD.text = alternativa4[idPergunta];
in the fieldA, I want you to receive a random value between alternative1, alternative2, alternative3, alternative4. for example, Random says that in the field replyA.text receives alternative4, so respotaB.text cannot receive this alternative, Random would have to generate another alternative.
This code can be simplified: objects. Sort(Comparer<T>. Create((a, b) => r.Next(2)-1));
– Thiago
With this optimization you gain about 3~5 nano seconds per comparison. It is a practical solution and not the best one. Surely it is possible to optimize this further without using the sort algorithm (which is kind of stupid to sort in a LOL scrambled way)
– user178974
I believe the implementation of . Net is a Quick Sort, which is N Log N, but this is easily linearizable.
– user178974