-1
using System;

public class HCW
{
    public void Main()
    {
        for (int i=0;i<10;i++){
        Random rnd = new Random();
int ID = rnd.Next(1, 999); // creates a number between 1 and 12

            Console.WriteLine(ID);  }
}
}   

Im getting the same 10 generated number. how to make the 10 different unique numbers ?

user3499033
  • 41
  • 1
  • 1
  • 2

1 Answers1

0

You're not supposed to create new Random object every iteration, because it takes current time as a seed, which will won't change in such a short period. Just put the rnd initialisation outside the loop.

Random rnd = new Random();
for (int i=0;i<10;i++)
    Console.WriteLine(rnd.Next(1,999));
Tarec
  • 3,268
  • 4
  • 30
  • 47