jeudi 9 février 2017

Randomizing part of array in C#

Lets say I have an array of integers. I found out that I can randomize the order of the elements simply by doing:

Random rnd = new Random();
array = array.OrderBy(x => rnd.Next()).ToArray();

But lets say I want to keep the first and the last elements in their original place. Can I do it using the same approach (using OrderBy()) or do I need to re-think my situation?




Aucun commentaire:

Enregistrer un commentaire