lundi 15 mai 2017

How to retain the value generated by Random class in a variable in C#

I am trying to retain the value generated by Random class and use it for the required steps in my code.

Here it is

Random random = new Random();
code = random.Next(100000, 999999);
Console.WriteLine("Value 1 : "+code);
Console.WriteLine("Value 2 : "+code);

The problem is when I call the first Console, it prints a random value. And then the second Console prints another random value which I dont want. I want to retain the first generated value and use it in my code further.

Any suggestions would be of great help.




Aucun commentaire:

Enregistrer un commentaire