Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Example
- {
- public static void Main()
- {
- int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- Console.WriteLine("До перемешивания: ");
- BeforeShuffle(array);
- Console.WriteLine("\nПосле перемешивания: ");
- Shuffle(array);
- Console.ReadKey();
- }
- static void BeforeShuffle(int[] array)
- {
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- }
- static void Shuffle(int[] array)
- {
- for (int i = 0; i < array.Length; i++)
- {
- Random random = new Random();
- int currenValue = array[i];
- int randomIndex = random.Next(i, array.Length);
- array[i] = array[randomIndex];
- array[randomIndex] = currenValue;
- Console.Write(array[i] + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement