C# Randomize Char Array with Programming Example

In C#, there is a way to randomize char array. Following program explains it clearly.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace array_sort
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] a = { '1', 'A', '2', 'B', '3', 'C' };
            char[] randomArray = new char[a.Length];
            int randomnumber;

            Random rnd = new Random();
            for (int i = a.Length; i >= 1; i--)
            {
                randomnumber = rnd.Next(1, i + 1) - 1;
                randomArray[i - 1] = a[randomnumber];
                a[randomnumber] = a[i - 1];
            }
            foreach (char s in randomArray)
            {
                Console.Write(s + " , ");
            }
            Console.ReadKey();
        }        
    }
}

Output

3 , 2 , 1 , A , C , B ,
_
 
More Examples
Write A Program To Print One Dimensional Array In Reverse Order
Write A Program To Sort One Dimensional Array In Descending Order Using Non Static Method.
Write A Program To Sort One Dimensional Array In Desending Order Static Class Array Method.
Write A Program To Sort One Dimensional Array In Ascending Order Using Non Static Method.
Write A Program To Sort One Dimensional Array In Ascending Order Using Static Method.
Write A Program To Add The Diagonal Of Two-Dimensional Array.
 
 

Share your thought