kirililchev3

RandomList Class

Mar 11th, 2019
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace CustomRandomList
  6. {
  7.     public class RandomList : List<string>
  8.     {
  9.         private Random random;
  10.  
  11.         public RandomList()
  12.         {
  13.             this.random = new Random();
  14.         }
  15.  
  16.         public string RemoveRandom()
  17.         {
  18.             int index = random.Next(0, this.Count);
  19.             string element = this[index];
  20.             this.RemoveAt(index);
  21.  
  22.             return element;
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment