Stefania
0
Q:

c# random generator

Random rnd = new Random();
int month  = rnd.Next(1, 13);  // creates a number between 1 and 12
int dice   = rnd.Next(1, 7);   // creates a number between 1 and 6
int card   = rnd.Next(52);     // creates a number between 0 and 51
16
int random_number = new Random().Next(1, 10) // Generates a number between 1 to 10
4
// One string will be randomly picked and displayed 
Random rnd = new Random();
string[] secOptions = {"string one", "string two", "string three"};
int randomNuber = rnd.Next(0, 3);
string secText = secOptions[randomNuber];
Console.WriteLine(secText);
2
// Creates a random number between 1 and 10
int randomNumber = new Random().Next(1, 11);
0
  private void RandName()
  {
        string[] maleNames = new string[1000] { "aaron", "abdul", "abe", "abel", "abraham", "adam", "adan", "adolfo", "adolph", "adrian"};
        string[] femaleNames = new string[1000] { "abby", "abigail", "adele", "adrian"};
        string[] lastNames = new string[1000] { "abbott", "acosta", "adams", "adkins", "aguilar"};

        Random rand = new Random(DateTime.Now.Second);
        if (rand.Next(1, 2) == 1)
        {
            FirstName = maleNames[rand.Next(0, maleNames.Length - 1)];
        }
        else
        {
            FirstName = femaleNames[rand.Next(0, femaleNames.Length - 1)];
        }

  }
0
Random numberGen = new Random();
int amountToOutput = 4;
int minimumRange = 1;
int maximumRange = 20;

for(int i = 0; i < amountToOutput; i++)
{
  int randomNumber = numberGen.Next(minimumRange, maximumRange);
  Console.WriteLine(randomNumber);
}
0
Random rnd = new Random();
int number  = rnd.Next(1, 10);
1

New to Communities?

Join the community