I am working on a console app that randomly selects 2 exercises from an array of exercises and uses them later in a tabata workout. I keep running into issues and the 2 selections are always the same.
Please keep your answers pretty simple as I am a beginner.
string[] tbExercises = new string[] { "Pushups", "Pullups", "Situps", "Mountain Climbers", "Burpees", "Goblet Squats", "Kettlebell Swings" };
List<string> randomExercises = new List<string>();
Random rnd1 = new Random();
string ex1 = tbExercises[rnd1.Next(0, 6)];
randomExercises.Add(ex1);
Random rnd2 = new Random();
string ex2 = tbExercises[rnd2.Next(0, 6)];
randomExercises.Add(ex2);
randomExercises.ForEach(Console.WriteLine);
Randomeach time. don't do that; reuse the same one.Randomclass in such close proximity causes them to have the same seed (which is based on the system's clock) - and that's why they give out the exact same pseudo-random sequence of numbers.If you will removernd2and use the sameRandominstance fromrnd1, you'll increase your chances of getting a different number from 0% to some positive percentage. However, that percentage is still going to be lower than 100%.