Auto generate Random number in c#
using System;
namespace Test_Application
{
class Program
{
static void Main(string[] args)
{
Random r = new Random();
Console.WriteLine("Enter Limits to Auto Generate numbers : ");
int x = int.Parse(Console.ReadLine());
Console.WriteLine("Wants one by one to Generate numbers, so press y or if not n : ");
string z = Console.ReadLine();
for (int i = 1; i <= x; i++)
{
int n = r.Next();
if (z == "y")
{
Console.WriteLine(n);
Console.ReadLine();
}
else
{
Console.WriteLine(n);
}
}
Console.ReadLine();
}
}
}
Output:
Enter Limits to Auto Generate numbers :3
Wants one by one to Generate numbers, so press y or if not n : n
123123213222
332121312321
422312131232
using System;
namespace Test_Application
{
class Program
{
static void Main(string[] args)
{
Random r = new Random();
Console.WriteLine("Enter Limits to Auto Generate numbers : ");
int x = int.Parse(Console.ReadLine());
Console.WriteLine("Wants one by one to Generate numbers, so press y or if not n : ");
string z = Console.ReadLine();
for (int i = 1; i <= x; i++)
{
int n = r.Next();
if (z == "y")
{
Console.WriteLine(n);
Console.ReadLine();
}
else
{
Console.WriteLine(n);
}
}
Console.ReadLine();
}
}
}
Output:
Enter Limits to Auto Generate numbers :3
Wants one by one to Generate numbers, so press y or if not n : n
123123213222
332121312321
422312131232