Advertisement
loleckek228

4.7

Sep 15th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _4._7
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] integers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  10.  
  11.             writeArray(integers);
  12.             Console.WriteLine();
  13.             shuffle(ref integers);
  14.             writeArray(integers);
  15.         }
  16.  
  17.         static void shuffle(ref int[] array)
  18.         {
  19.             Random random = new Random();
  20.  
  21.             for (int i = array.Length - 1; i > 0; i--)
  22.             {
  23.                 int randomValue = random.Next(i);
  24.                 int value = array[i];
  25.                 array[i] = array[randomValue];
  26.                 array[randomValue] = value;
  27.             }
  28.         }
  29.  
  30.         static void writeArray(int[] array)
  31.         {
  32.             for (int i = 0; i < array.Length; i++)
  33.             {
  34.                 Console.Write(array[i] + " ");
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement