+ 1
Whats the code for random numbers
for example: you create the code for random and you want to make numbers generated 20-40 or 0-10
2 Réponses
+ 7
Random rnd = new Random();
//^^^ is the random number generator
int y = 20; //This is the min value
int x = 40; //This is the max value
int z = rnd.Next(y, x));
//z will then be the result from random number generator. Alternatively, instead of writing 'x, y', you can just directly put the value in, like Andreas method. However, directly putting the values in disables you from changing the value if you want the available numbers inside the random number generator to change in a certain condition.
Console.WriteLine(z);
//this is if you want to write out the result in the console.
+ 4
Random rand = new Random();
int x = rand.Next(0, 10);
int y = rand.Next(20, 40);