Answers for "random number generator without duplicates c#"

C#
0

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
}
Posted by: Guest on June-16-2021

Code answers related to "random number generator without duplicates c#"

C# Answers by Framework

Browse Popular Code Answers by Language