Post

# Random number Generator

Oct 24 2014 7:13 AM Hi Can anyone help me, i am trying the build a deck of Crads the problem i am having is producing enough random numbers to fill the deck i get to 16 cards and then it seems i am not producing the remaining cards i need to fill the deck.

code is below..........

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TexasHoldEmTest
{
public enum Suit { Clubs = 1, Diamonds = 2, Hearts = 3, Spades = 4 }

public enum CardNumber { Ace = 1, Two = 2, Three = 3, Four = 4, Five = 5, Six = 6, Seven = 7, Eight = 8, Nine = 9, Ten = 10, Jack = 11, Queen = 12, King = 13 }

public class Card
{
public Suit suit;
public CardNumber number;
public bool isUsed = false;

public Card()
{
// default constuctor that returns type of the Card class

Random suit1 = new Random();
Random number1 = new Random();

suit = (Suit)suit1.Next(1, 5);
number = (CardNumber)number1.Next(1, 14);
}

public void showCard(List<Card> c)
{
Console.WriteLine("{0} of {1}",number, suit);

}

public void Deck(List<Card> c)
{
do
{
Card card = new Card();
bool exists = c.Exists(x => x.suit == card.suit && x.number == card.number);
if (exists == false)
{
Console.WriteLine("Generating Card {0}", c.Count);
}
}
while (c.Count < 52);
}
}

class Game
{
static void Main(string[] args)
{
Card card = new Card();
List<Card> deckOfCards = new List<Card>();

card.Deck(deckOfCards);

foreach (Card c in deckOfCards)
{
c.showCard(deckOfCards);
}