Hi guys i need some help here i want to distribute 6 strings randomly in 6 buttons as text without any repetition. That is i Want to do some kind of shuffling and distribute it but there will no duplicates each button will hold a unique string. If anyone could post the code it would be great 🙂 Thank you
class Card_Deck
{
public Random r;
public string ReceiveCards()
{
List<string> cards = new List<string>();
cards.Add("♣ King");
cards.Add("♦ King");
cards.Add("♥ King");
cards.Add("♠ King");
cards.Add("♣ Jack");
cards.Add("♦ Jack");
int index = r.Next(cards.Count);
var card = cards[index];
cards.RemoveAt(index);
return card;
}
}
}
This is in the main form
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Card_Deck cd = new Card_Deck() { r = new Random(DateTime.Now.Millisecond) };
button1.Text = cd.ReceiveCards();
button2.Text = cd.ReceiveCards();
button3.Text = cd.ReceiveCards();
button4.Text = cd.ReceiveCards();
button5.Text = cd.ReceiveCards();
button6.Text = cd.ReceiveCards();
}
}
}
1 Answer