Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- int[] arrayNumbers = { 1, 2, 3, 4, 5, 6, };
- Console.WriteLine("Исходный массив: ");
- ShowArray(arrayNumbers);
- Console.WriteLine("\n\nПремешанный массив: ");
- Shuffle(arrayNumbers);
- ShowArray(arrayNumbers);
- Console.WriteLine("\n");
- }
- private static void Shuffle(int[] array)
- {
- Random random = new Random();
- for (int i = array.Length - 1; i >= 0; i--)
- {
- int randomIndexPosition = random.Next(i + 1);
- int tempItem = array[randomIndexPosition];
- array[randomIndexPosition] = array[i];
- array[i] = tempItem;
- }
- }
- private static void ShowArray(int[] array)
- {
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement