C#List随机交换取数据(C#实现的洗牌算法)

阅读更多

C#实现的洗牌算法

 

 

 

///


/// 洗牌算法
///

///
///
public void Reshuffle(List listtemp)
{
//随机交换
Random ram = new Random();
int currentIndex;
T tempValue;
for (int i = 0; i < listtemp.Count; i++)
{
currentIndex = ram.Next(0, listtemp.Count - i);
tempValue = listtemp[currentIndex];
listtemp[currentIndex] = listtemp[listtemp.Count - 1 - i];
listtemp[listtemp.Count - 1 - i] = tempValue;
}
}


你可能感兴趣的:(c#)