Advertisement
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 ConsoleApp3
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- Console.Write("Дан массив: ");
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- Console.WriteLine();
- Shuffle(array);
- Console.Write("Канзас сити шафл: ");
- for (int i=0;i<array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- Console.WriteLine();
- Console.ReadKey();
- }
- static void Shuffle(int[] array)
- {
- Random rnd = new Random();
- for (int i = array.Length - 1; i >= 1; i--)
- {
- int j = rnd.Next(i + 1);
- var temp = array[j];
- array[j] = array[i];
- array[i] = temp;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement