TheBulgarianWolf

Randomize Words

Jan 2nd, 2021
871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ClassesAndObjects
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Random random = new Random();
  10.             string[] input = Console.ReadLine().Split(" ");
  11.             for(int i = 0; i < input.Length; i++)
  12.             {
  13.                 int index = random.Next(i, input.Length);
  14.                 string help = input[i];
  15.                 input[i] = input[index];
  16.                 input[index] = help;
  17.             }
  18.  
  19.             foreach(string word in input)
  20.             {
  21.                 Console.WriteLine(word);
  22.             }
  23.         }
  24.     }
  25. }
  26.  
Add Comment
Please, Sign In to add comment