kirililchev3

Randomize Word

Jun 13th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace P02_Randomize_Word
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] words = Console.ReadLine().Split(' ');
  11.  
  12.             Random rnd = new Random();
  13.  
  14.             for (int i = 0; i < words.Length; i++)
  15.             {
  16.                 var currentWord = words[i];
  17.                 var randomIndex = rnd.Next(0, words.Length);
  18.                 var randomWord = words[randomIndex];
  19.                 words[i] = randomWord;
  20.                 words[randomIndex] = currentWord;
  21.             }
  22.             Console.WriteLine(string.Join(Environment.NewLine, words));
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment