Jump to content

Playing cards: Difference between revisions

Line 347:
 
public void Shuffle() {
// using Knuth Shuffle (see at http://rosettacode.org/wiki/Knuth_shuffle)
// HACK: Sort with a custom comparator. (A random number between -1 and 1.)
Random rrandom = new System.Random();
Card temp;
tryint {j;
this.deck.Sort(delegate { return r.Next(-1, 1); });
for (int i = 0; i < deck.Count; i++){
}
j = random.Next(deck.Count);
catch {
this.Shuffle()temp = deck[i];
} deck[i] = deck[j];
deck[j] = temp;
}
}
 
public Card Deal() {
this.Shuffle();
Card r = this.deck[0];
this.deck.RemoveAt(0);
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.