Advertisement
Spocoman

01. Randomize Words

Mar 2nd, 2022
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. using System;
  2.  
  3. namespace RandomizeWords
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string[] words = Console.ReadLine().Split();
  10.  
  11.             Random rnd = new Random();
  12.  
  13.             for (int pos1 = 0; pos1 < words.Length; pos1++)
  14.             {
  15.                 int pos2 = rnd.Next(words.Length);
  16.                 for (int j = pos2; j < words.Length; j++)
  17.                 {
  18.                     string word = words[pos2];
  19.                     words[pos2] = words[pos1];
  20.                     words[pos1] = word;
  21.                 }
  22.  
  23.             }
  24.             Console.WriteLine(string.Join(Environment.NewLine, words));
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement