/// <summary>
/// 洗牌算法:先給一個一維數組賦值1~10,然後隨即打亂這個數組。最簡單得就是用冒泡算法來打亂。
/// </summary>
public void XiPaiSuanFa()
{
int[] cards = new int[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
Random ram = new Random();
int currentIndex;
int tempValue;
for (int i = 0; i < 10; i++)
{
currentIndex = ram.Next(0, 10 - i);
tempValue = cards[currentIndex];
cards[currentIndex] = cards[9 - i];
cards[9 - i] = tempValue;
}
}
/// 洗牌算法:先給一個一維數組賦值1~10,然後隨即打亂這個數組。最簡單得就是用冒泡算法來打亂。
/// </summary>
public void XiPaiSuanFa()
{
int[] cards = new int[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
Random ram = new Random();
int currentIndex;
int tempValue;
for (int i = 0; i < 10; i++)
{
currentIndex = ram.Next(0, 10 - i);
tempValue = cards[currentIndex];
cards[currentIndex] = cards[9 - i];
cards[9 - i] = tempValue;
}
}
浙公网安备 33010602011771号