Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Shuffler
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] words = {"apple","orange","tomato","island","carrot"};
- Shuffle(words);
- foreach (string word in words)
- {
- Console.Write($"{word} ");
- }
- Console.ReadKey();
- }
- private static void Shuffle(string[] array)
- {
- Random rand = new Random();
- for (int i = 0; i < array.Length; i++)
- {
- int randomIndex = rand.Next(0,array.Length);
- int randomIndex2 = rand.Next(0,array.Length);
- string temp = array[randomIndex];
- array[randomIndex] = array[randomIndex2];
- array[randomIndex2] = temp;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment