Advertisement
Masovski

[C# Basics][Loops-HW] 11. Random Numbers in Given Range

Mar 29th, 2014
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. using System;
  2.  
  3. class RandomNumbersInGivenRange
  4. {
  5.     static void Main()
  6.     {
  7.         int n = int.Parse(Console.ReadLine());
  8.         int min = int.Parse(Console.ReadLine());
  9.         int max = int.Parse(Console.ReadLine());
  10.         bool inRange = min <= max;
  11.  
  12.         if (inRange)
  13.         {
  14.             max += 1;
  15.  
  16.             Random randomGenerator = new Random();
  17.  
  18.             for (int i = 0; i <= n; i++)
  19.             {
  20.                 int randomNumber = randomGenerator.Next(min, max);
  21.                 Console.Write(randomNumber + " ");
  22.             }
  23.             Console.WriteLine();
  24.         }
  25.         else
  26.         {
  27.             Console.WriteLine("Invalid input. Correct input --> min <= max");
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement