-1

In this for loop I keep getting same value from my Random Function. How can I get the Random Function to be actually Random?

for (int i=0; i<50; i++){
Random random = new Random();
int randomSong = random.Next(0, songList.Count - 1);
var selectedSong = songList.ElementAt(randomSong);
}

1 Answers1

0

You need to define Random outside of the loop.

var rand = new Random();
for (int x = 0; x<50;x++)
{
    var song = list.ElementAt(rand.Next(list.Count()));
}