日期:2014-05-18 浏览次数:21266 次
public void shuffle()
{
Card[] newDeck = new Card[52];
bool[] assigned = new bool[52];
Random sourceGen = new Random();
for (int i = 0; i < 52; i++)
{
int destCard = 0;
bool foundCard = false;
while (foundCard == false)
{
destCard = sourceGen.Next(52);
if (assigned[destCard] == false)
foundCard = true;
}
assigned[destCard] = true;
newDeck[destCard] = cards[i];
}
newDeck.CopyTo(cards, 0);
}
List<int> oldcard = new List<int>()
{1,2,3,4,5,6....};
List<int> newcard = new List<int>();
Random r = new Random();
while (oldcard.Count > 0)
{
n = r.Next(0,oldcard.Count);
newcard.Add(oldcard[n]);
oldcard.RemoveAt(n);
}
------解决方案--------------------
int[] result = Enumerable.Range(1, 52)
.Select(x => new { r = Guid.NewGuid().ToString(), v = x })
.ToList()
.OrderBy(x => x.r)
.Select(x => x.v)
.ToArray();