shuffle (rearrange randomly) a List<string>

<>

This question already has an answer here:

Answers


List<Foo> source = ...
var rnd = new Random();
var result = source.OrderBy(item => rnd.Next());

Obviously if you want real randomness instead of pseudo-random number generator you could use RNGCryptoServiceProvider instead of Random.


This is an extension method that will shuffle a List<T>:

    public static void Shuffle<T>(this IList<T> list) {
        int n = list.Count;
        Random rnd = new Random();
        while (n > 1) {
            int k = (rnd.Next(0, n) % n);
            n--;
            T value = list[k];
            list[k] = list[n];
            list[n] = value;
        }
    }

Need Your Help

Use LSTM tutorial code to predict next word in a sentence?

python tensorflow lstm word2vec word-embedding

I've been trying to understand the sample code with https://www.tensorflow.org/tutorials/recurrent

How to create a dynamic file + link for download in Javascript?

javascript file dynamic download creation

Typically, HTML pages can have link to documents (PDF, etc...) which can be downloaded from the server.