Ask Your Question
1

How can a list of arrays be permuted in C#?

asked 2021-08-14 11:00:00 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-06-05 17:00:00 +0000

devzero gravatar image

In C#, you can permute a list of arrays by using the Fisher-Yates shuffle algorithm. Here is an example implementation of the algorithm:

# public static void ShuffleList(List<int[]> list) { Random random = new Random(); int n = list.Count; while (n > 1) { n--; int k = random.Next(n + 1); int[] value = list[k]; list[k] = list[n]; list[n] = value; } }

This code shuffles the list by swapping each element with a random element that comes after it. To use this method, simply pass a list of integer arrays to the ShuffleList function.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-08-14 11:00:00 +0000

Seen: 16 times

Last updated: Jun 05 '21