Languages
[Edit]
EN

C#/.NET - random int

12 points
Created by:
Kate_C
2854

In C#/.NET is possible to generate random int in few ways.

1. Random int example

Random random = new Random();
int value = random.Next();
Console.WriteLine(value);

Output:

1069169069

2. Random int with max value example

Random random = new Random();
int value = random.Next(100);
Console.WriteLine(value);

Output:

58
Note: random value will be from 0 to 99 (100-1).

3. Random int from range example

Random random = new Random();
int value = random.Next(10 + 1, 100 + 1);
Console.WriteLine(value);

Output:

34
Note: random value will be from 11 to 100.
Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.