Advertisement
SLENSER

Untitled

May 22nd, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 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.  
  7. namespace _4_6
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Random r = new Random();
  14.  
  15.             //int[] array = new int[30];
  16.             int[] array = {2,4,6,2,5,45,3 };
  17.  
  18.             /*for (int i = 0; i < array.Length; i++)
  19.             {
  20.                 array[i] = r.Next(0, 78);
  21.                 Console.Write(array[i] + " ");
  22.             }*/
  23.             for (int i = 0; i < array.Length; i++)
  24.                 Console.Write(array[i] + " ");
  25.             Console.WriteLine();
  26.  
  27.             Shuffle(array);
  28.  
  29.             for (int i = 0; i < array.Length; i++)
  30.             {
  31.  
  32.                 Console.Write(array[i] + " ");
  33.             }
  34.             Console.WriteLine();
  35.         }
  36.         static void Shuffle(int[] array)
  37.         {
  38.             Random r = new Random();
  39.  
  40.             for (int i = array.Length - 1; i >= 1 ; i--)
  41.             {
  42.                 int random = r.Next(i + 1);
  43.                 int t = array[random];
  44.                 array[random] = array[i];
  45.                 array[i] = t;
  46.             }
  47.         }
  48.        
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement