Advertisement
Nikolay_Kashev

Randomize Words (second solution)

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