random number generator without duplicates c#
using System.Linq;
public int range;
public int MyNum[];
public int KnownNumbers[];
public int UniqueNumbers;
private void MyNumbers()
{
MyNum = new int[range];
for (int i = 0; i < range; i++)
{
MyNum[i] = i;
}
}
private void RandomDiffNumber()
{
KnownNumbers = new int[UniqueNumbers];
int Cmax = MyNum.Length;
for (int i = 0; i < UniqueNumbers; i++)
{
Cmax = MyNum.Length;
int rand = Random.Range(0,Cmax);
KnownNumbers[i] = MyNum[rand];
MyNum = MyNum.Where((source, index) => index != rand).ToArray();
}
// Now KnownNumbers contain unique Random Numbers
}