Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Shuffle
- {
- class Program
- {
- static void Main(string[] args)
- {
- int arrayLength = Convert.ToInt32(Console.ReadLine());
- int[] array = new int[arrayLength];
- array = FillArray(array);
- ShowArray(array);
- Shuffle(array);
- Console.WriteLine();
- ShowArray(array);
- }
- static int[] FillArray(int[] array)
- {
- var random = new Random();
- for(int i = 0; i < array.Length; i++)
- {
- array[i] = random.Next(10);
- }
- return array;
- }
- static void ShowArray(int[] array)
- {
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write($"{array[i]} ");
- }
- }
- static void Shuffle(int[] array)
- {
- var random = new Random();
- for (int i = 0; i < array.Length; i++)
- {
- int key = array[i];
- int posRandom = random.Next(i, array.Length);
- array[i] = array[posRandom];
- array[posRandom] = key;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment