Advertisement
alexey3017

Untitled

Mar 23rd, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Learn1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  13.             Shuffle(array);
  14.         }
  15.  
  16.         static void Shuffle(int[] array)
  17.         {
  18.             Random rand = new Random();
  19.             for (int i = array.Length - 1; i >= 1; i--)
  20.             {
  21.                 int tempVariable = rand.Next(i + 1);
  22.                 int tempNumber = array[tempVariable];
  23.                 array[tempVariable] = array[i];
  24.                 array[i] = tempNumber;
  25.             }
  26.             for (int i = 0; i < array.Length; i++)
  27.             {
  28.                 Console.Write(array[i]);
  29.             }
  30.         }
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement