Answers for "how to use shuffle for collection in c sharp"

C#
3

c# list shuffle

var rnd = new Random();
var randomized = list.OrderBy(item => rnd.Next());
Posted by: Guest on July-22-2021
0

c# shuffle array

# cCopyusing System;
using System.Linq;
using System.Security.Cryptography;

namespace randomize_array
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = { 1, 2, 3, 4, 5 };
            Random random = new Random();
            arr = arr.OrderBy(x => random.Next()).ToArray();
            foreach (var i in arr)
            {
                Console.WriteLine(i);
            }
        }
    }
}

3
4
5
1
2
Posted by: Guest on October-06-2021

C# Answers by Framework

Browse Popular Code Answers by Language