Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Shuffle
- {
- class Program
- {
- static void Main(string[] args)
- {
- Random rand = new Random();
- int[] array = new int[9] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- Shuffle(array, rand);
- for(int i = 0; i < array.Length; i++)
- {
- Console.Write($"{array[i]} ");
- }
- Console.WriteLine();
- }
- static void Shuffle(int[] array, Random rand)
- {
- int exchVar;
- int replaceIndex;
- for(int i = 0; i < array.Length - 1; i++)
- {
- replaceIndex = rand.Next(i + 1, array.Length);
- exchVar = array[replaceIndex];
- array[replaceIndex] = array[i];
- array[i] = exchVar;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment