class MyOwnRandom
{
List<int> alreadyCalledNumbers = new List<int>();
Random random = new Random();
public int next(int min, int max)
{
int randomNumber;
randomNumber = random.Next(min,max);
while(alreadyCalledNumbers.Contains(randomNumber))
{
randomNumber = random.Next(min, max);
}
alreadyCalledNumbers.Add(randomNumber);
return randomNumber;
}
public int next(int max)
{
int randomNumber;
randomNumber = random.Next(max);
while (alreadyCalledNumbers.Contains(randomNumber))
{
randomNumber = random.Next(max);
}
alreadyCalledNumbers.Add(randomNumber);
return randomNumber;
}
public void reset()
{
alreadyCalledNumbers.Clear();
}
}

public class RandomizedCollection<TInput>
{
// Random provider
[ThreadStatic]
private static Random _random;
private static Random Random { get { return _random ?? (_random = new Random(System.Threading.Interlocked.Increment(ref _seed))); } }
private static int _seed = Environment.TickCount;
// Allow for progressive stepping through the collection, with lazy evaluation
private readonly IEnumerator<TInput> _enumerator;
private bool _hasNext;
public bool HasNext { get { return _hasNext; } }
public RandomizedCollection(IEnumerable<TInput> original)
{
_enumerator = original.OrderBy(t => Random.Next()).GetEnumerator();
_hasNext = _enumerator.MoveNext(); // move to the beginning of the collection
}
public TInput Next()
{
if (!_hasNext)
throw new InvalidOperationException("Reached the end of the collection");
var value = _enumerator.Current;
_hasNext = _enumerator.MoveNext();
return value;
}
};
var stuff = new[] {
"hello",
"world",
"this",
"is",
"a",
"random",
"string",
"array"
};
var randomized = new RandomizedCollection<string>(stuff);
while(randomized.HasNext())
Console.WriteLine(randomized.Next());
Console.Read();
var rnd = new Random(Environment.TickCount);
foreach(var item in stuff.OrderBy(s => rnd.Next()))
Console.WriteLine(item);