Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

Shuffle Array C#

using System;
using System.Linq;
using System.Security.Cryptography;

{
    class Program
    {
        static void Main(string[] args)
        {
        	//Array of int
            int[] arr = { 1, 2, 3, 4, 5 };
            //Assigned the function 'Random()' to 'random'
            Random random = new Random();
            //generated a random index with 'random.Next()' and placed every int in a 
            //random index with 'OrderBy()'
            //converted the data in an array with 'ToArray()'
            arr = arr.OrderBy(x => random.Next()).ToArray();
            
            //Stamp the results
            foreach (var i in arr)
            {
                Console.WriteLine(i);
            }
        }
    }
}
Source by www.delftstack.com #
 
PREVIOUS NEXT
Tagged: #Shuffle #Array
ADD COMMENT
Topic
Name
6+1 =