- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Generating random numbers in C#
To generate random numbers, use Random class.
Create an object −
Random r = new Random();
Now, use the Next() method to get random numbers in between a range −
r.Next(10,50);
The following is the complete code −
Example
using System; public class Program { public static void Main() { Random r = new Random(); int genRand= r.Next(10,50); Console.WriteLine("Random Number = "+genRand); } }
Output
Random Number = 24
Advertisements