Okay ... mình tìm được cái function này cho bạn
Code:
private List<string> MixList(List<string> inputList)
{
List<string> randomList = new List<string>();
if (inputList.Count == 0)
return randomList;
Random r = new Random();
int randomIndex = 0;
while (inputList.Count > 0)
{
randomIndex = r.Next(0, inputList.Count); //Choose a random object in the list
randomList.Add(inputList[randomIndex]); //add it to the new, random list<
inputList.RemoveAt(randomIndex); //remove to avoid duplicates
}
//clean up
inputList.Clear();
inputList = null;
r = null;
return randomList; //return the new random list
}
Ví dụ bạn có: z1, z2,z3, z4 la` cÂu trả lời
List<String> lstAnswers = new List<String>
lstAnswers.add('z1');
lstAnswers.add('z2');
lstAnswers.add('z3');
lstAnswers.add('z4');
List<String> lstMix = this.MixList(lstAnswers);
gio*` ne^'u ba.n print out thi` ca'i lít cu?a ba.n nó bị mix lại ... shuffle hoặc bị xào !!
Chúc bạn thành công!
Bookmarks