Random numbers are started from a seed value: normally the system clock. So it shouldn't matter what you do as long as you don't start the random number generator at the same time!
In C#, it's pretty easy: a class level (possibly even
static
) instance of the Random class:
private Random rand = new Random();
Then use it to generate your numbers when you want:
for (int i = 0; i < 100; i++)
{
int r = rand.Next();
Console.WriteLine(r);
}
Should prove the sequence is different for each execution of your code.
If you want a single unique number for each execution, then Id suggest using a Guid instead:
Guid id = Guid.NewGuid();
as these are very, very unlikely to be duplicated.