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.
 

More Articles

 

Share your thought



PLEASE DISABLE ADBLOCKER AND SUPPORT US!

Please support us by enabling ads on this page. Refresh

YOU DON'T LIKE ADS, WE ALSO DON'T LIKE ADS!
 
But we have to show ads on our site to keep it free and updated. We have to pay huge server costs, domain costs, CDN Costs, Developer Costs, Electricity and Internet Bill. Your little contribution will encourage us to regularly update this site.