Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace C_sharp_Light
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = new int[10];
- Console.WriteLine("Массив до перемешивания");
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = i;
- Console.Write(array[i]+" ");
- }
- Console.WriteLine();
- Shuffle(array);
- Console.WriteLine("Массив после перемешивания");
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- Console.ReadKey();
- }
- static void Shuffle(int[] array)
- {
- Random rand = new Random();
- int temp, posOne, posTwo;
- for (int i = 0; i < array.Length*2; i++)
- {
- posOne = rand.Next(0, array.Length);
- posTwo = rand.Next(0, array.Length);
- while (posOne == posTwo)
- {
- posTwo = rand.Next(0, array.Length);
- }
- temp = array[posOne];
- array[posOne] = array[posTwo];
- array[posTwo] = temp;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement