Languages
[Edit]
EN

C#/.NET - generate random int

12 points
Created by:
Theodora-Battle
528

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.
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

C# / .NET - random

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join