SHARE
TWEET

Shuffle

AlexStraga87 Feb 16th, 2020 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] array = new int[10];
  14.  
  15.             for (int i = 0; i < array.Length; i++)
  16.             {
  17.                 array[i] = i;
  18.             }
  19.  
  20.             Shuffle(ref array, 3);
  21.  
  22.             for (int i = 0; i < array.Length; i++)
  23.             {
  24.                 Console.Write(array[i] + " ");
  25.             }
  26.  
  27.             Console.ReadKey();
  28.         }
  29.  
  30.         static void Shuffle(ref int[] array, byte iterationCount = 1)
  31.         {
  32.             Random rand = new Random();
  33.             int value;
  34.             int randindex;
  35.             for (int j = 0; j < iterationCount; j++)
  36.             {
  37.                 for (int i = 0; i < array.Length; i++)
  38.                 {
  39.                     randindex = rand.Next(0, array.Length);
  40.                     value = array[i];
  41.                     array[i] = array[randindex];
  42.                     array[randindex] = value;
  43.                 }
  44.             }
  45.  
  46.         }
  47.     }
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top