I have two string lists en
and en1
List<string> en = new List<string>(new string[] { "horse", "cat", "dog", "milk", "honey"});
List<string> en1 = new List<string>(new string[] { "horse1", "cat2", "dog3", "milk4", "honey5" });
And I want radomize their content "Shuffle them" and put this radomized content to new two lists. But I also want them randomize same way so lists after randomization will still be
en[0] == en1[0]
random content after randomization
{ "cat", "horse", "honey", "milk", "dog"}
{ "cat2", "horse1", "honey5", "milk4", "dog3"}
Two obvious ways:
The second sounds cleaner to me. You'd use something like:
var joined = en.Zip(en1, (x, y) => new { x, y }).ToList();
var shuffled = joined.Shuffle(); // Assume this exists
en = shuffled.Select(pair => pair.x).ToList();
en1 = shuffled.Select(pair => pair.y).ToList();
See more on this question at Stackoverflow