mardi 19 mai 2015

How to make c# Random Numbers repeat

I'm trying to generate random arrays to test my homework assignments. The Problem is that the numbers generated are always unique , and I need some repeating numbers from time to time.

Here is the code I came up with:

static int[] RandomIntArray()
{
    Random rnd = new Random();
    Console.Write("Enter array Length: ");
    int n = int.Parse(Console.ReadLine());
    int[] arr = new int[n];

    for (int i = 0; i < arr.Length; i++)
    {
        arr[i] = rnd.Next(short.MinValue, short.MaxValue);
    }

    return arr;
}




Aucun commentaire:

Enregistrer un commentaire