0

I have an array. I would like to write its items in a random order every time I call. My array is this.

string[] a= {"A","B","C","D","F"};
string[] a= new string[5];

For example the order should be like this

C D F A B

But it should change the order.

Matsemann
  • 21,083
  • 19
  • 56
  • 89
user2569038
  • 33
  • 1
  • 8

1 Answers1

1

You can try it like this:

string[] a = { "A", "B", "C", "D", "F" };
Random rand = new Random();
string[] RandArray = a.OrderBy(x => Guid.NewGuid()).ToArray();
string[] RandArray = a.OrderBy(x => rand.Next()).ToArray();
//any of these works.
terrybozzio
  • 4,424
  • 1
  • 19
  • 25