You're problem is that you are creating two different Random
instances. By default, if you do not supply a seed number, the current time will be used as a seed. However, you're code is executing so quickly, that the same time is being used as a seed (because you're code is executing faster than the smallest resolution of the clock), so the number you receive is the same each time.
The best fix is to create only a single instance of Random
. For example, you could change your code to:
public class Kort
{
public static System.Random KortNummer = new System.Random();
public int FåKortNummer()//Get card number
{
int kort = KortNummer.Next(1, 14);
ErKortTrukket(kort);//is drawn
return kort;
}
}