I was making a loop that picks the correct 9th element of an array randomly each time it loops through.
There are 99 elements in my loop in total.
Each 9th element will be the same( % 9 ). I need to make the rest 90 of them loop randomly each time i open the application.
Check my code:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
string[] assignments = new string[] { "https://cdn2.iconfinder.com/data/icons/animals/48/Turtle.png", "https://cdn2.iconfinder.com/data/icons/animals/48/Butterfly.png", "https://cdn2.iconfinder.com/data/icons/animals/48/Dolphin.png", "https://cdn2.iconfinder.com/data/icons/animals/48/Elephant.png", "https://cdn2.iconfinder.com/data/icons/animals/48/Hippopotamus.png", "https://cdn2.iconfinder.com/data/icons/animals/48/Panda.png" };
Random rnd = new Random();
string[] randomingArray = assignments.OrderBy(x => rnd.Next()).ToArray();
string repeatNumber = "";
List<string> animals = new List<string>();
for (int i = 1; i < 100; i++)
{
if (i == 9)
{
repeatNumber = randomingArray[i % randomingArray.Length];
animals.Add(repeatNumber);
}
else if ((i % 9) == 0)
{
animals.Add(repeatNumber);
}
else
{
// random animals.Add(); <-- it should loop randomly here.
}
ItemsControl1.ItemsSource = animals;
}
}
}
After that i add my elements to a list and send that list to xaml via binding.