C
C#2y ago
kiran

❔ Blackjack card randomizer

public static void Blackjack() { Console.Clear(); int card1 = 0; int card2 = 0; int card3 = 0; while (true) { Random random1 = new Random(); card1 = random1.Next(1, 11); Random random2 = new Random(); card2 = random2.Next(1, 11); Console.WriteLine("your cards: {0} and {1}", card1, card2); Console.WriteLine("do you want another card? y/n"); string hitstand = Convert.ToString(Console.ReadLine()); hitstand = hitstand.ToLower(); if (hitstand == "y") { Random random3 = new Random(); card3 = random3.Next(1, 11); } else if (hitstand == "n") { int cardtotal = card1 + card2 + card3; bjMath(cardtotal); } } i want to give the user 2 cards to begin with and they can keep picking cards that are random 1-10 ty 🙂
10 Replies
Anton
Anton2y ago
$code
MODiX
MODiX2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
Anton
Anton2y ago
Create the rng outside the loop, and reuse it each time
Angius
Angius2y ago
Or use the static instance, Random.Shared
D.Mentia
D.Mentia2y ago
A better way to do this would be to build an array/list/etc of 50 cards; 1-10 4 times, then 10 11's (for a cheap approximation). Or a bit extra effort to include suits. Then shuffle the collection (once) and you can easily give them 'cards' from it without having to mess with random anymore
pox
pox2y ago
Or use Random.Shared
kiran
kiran2y ago
How would i do that
Anton
Anton2y ago
google how to shuffle arrays
Angius
Angius2y ago
Fisher-Yates
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts