Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace HomeWorks
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- WriteArray(array);
- Shuffle(array);
- WriteArray(array);
- Console.ReadKey();
- }
- static void Shuffle(int[] array)
- {
- Random random = new Random();
- int tempValueIndex;
- int tempIndex;
- for(int i = 0; i < array.Length; i++)
- {
- tempValueIndex = array[i];
- tempIndex = random.Next(i, array.Length);
- array[i] = array[tempIndex];
- array[tempIndex] = tempValueIndex;
- }
- }
- static void WriteArray(int[] array)
- {
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- Console.WriteLine();
- }
- }
- }
Add Comment
Please, Sign In to add comment