From 3edbad46e4cf23bfca6e5e96636db4618a4173e0 Mon Sep 17 00:00:00 2001 From: KattaRoopa <88130575+KattaRoopa@users.noreply.github.com> Date: Fri, 13 Feb 2026 17:01:24 +0530 Subject: [PATCH] Update Deck.cs --- CSharp/Blackbaud.Interview.Cards/Deck.cs | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/CSharp/Blackbaud.Interview.Cards/Deck.cs b/CSharp/Blackbaud.Interview.Cards/Deck.cs index 7b55e56..dbb80a4 100644 --- a/CSharp/Blackbaud.Interview.Cards/Deck.cs +++ b/CSharp/Blackbaud.Interview.Cards/Deck.cs @@ -1,3 +1,7 @@ +using System; +using System.Collections.Generic; +using System.Linq; + namespace Blackbaud.Interview.Cards; /// @@ -56,6 +60,33 @@ public Card NextCard() { return null; } + /// + /// Shuffles the deck a given number of times and returns a new shuffled deck. + /// + public Deck Shuffle(int times) + { + if (times <= 0) + throw new ArgumentException("Number of shuffles must be greater than zero."); + + var cards = _stackOfCards.ToList(); + + var random = new Random(); + + for (int t = 0; t < times; t++) + { + for (int i = cards.Count - 1; i > 0; i--) + { + int j = random.Next(i + 1); + + var temp = cards[i]; + cards[i] = cards[j]; + cards[j] = temp; + } + } + + return new Deck(cards); + } + } }