The Random.Next() method is also available in the Random class which returns random numbers.
This Range() method requires parameters such as minimum and maximum number to set the range. In this example, I have taken the numbers (0, 4) in the range method, which contains the number - 0,1,2,3, i.e., a total of 4 numbers.
Whenever the Random.Next() method is executed on the above range, it will return the output in a random list, like 2,0,1,3 or 3,2,1,0 or 1,3,0,2 or 0,2,1,3 etc.
- var randomNumbers = Enumerable.Range(0, 4).OrderBy(x => rnd.Next()).Take(4).ToList();
On every click of “Shuffle” button, the above line of code will return the list of 4 numbers. The sequence gets changed everytime. By using this number, we can set the position of images.
As soon as the position of images has changed, it behaves like the images are shuffled.
We can apply the same for randomizing Controls, Pages, Tabs, Numbers, etc.
On click of the“Shuffle” button, it shuffles the pictures randomly.
Step 1
Step 2
Step 3
Step 4
Step 5
Step 6
- Enumerable.Range(0, 4).OrderBy(x => rnd.Next()).Take(4).ToList();
Source Code

Željko PerićPosted Mar 17, 2019, 3:35 AM
Good article.