using System;
using System.Linq;
namespace Loto
{
class Program
{
static void Main(string[] args)
{
short[] tirage = new short[6]; //array that contains the numbers
short nbTirage; //the number randomed
for (int i = 0; i < 6; i++)
{
nbTirage = NombreAleatoire();
while (tirage.Contains(nbTirage)) //if the number has already been drawn
{
nbTirage = NombreAleatoire(); //we random another one
}
Console.Write(nbTirage + " "); //writing the result
}
}
static short NombreAleatoire()
{
Random nb = new Random();
return (short)nb.Next(1, 49);
}
}
}
This is the full program.
It is supposed to draw 7 unique numbers between 1 and 49 included. The program works well in debug mode, but when i run it from the exe, it draw 7 times the same number. What is causing that ? I'm using Visual Studio.