Facebook
From Gracious Pelican, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 234
  1. using System;
  2.  
  3. public class Example
  4. {
  5.    public static void Main()
  6.    {
  7.       Random rnd = new Random();
  8.  
  9.       Console.WriteLine("\n20 random integers from -100 to 100:");
  10.       for (int ctr = 1; ctr <= 20; ctr++)
  11.       {
  12.          Console.Write("{0,6}", rnd.Next(-100, 101));
  13.          if (ctr % 5 == 0) Console.WriteLine();
  14.       }
  15.  
  16.       Console.WriteLine("\n20 random integers from 1000 to 10000:");      
  17.       for (int ctr = 1; ctr <= 20; ctr++)
  18.       {
  19.          Console.Write("{0,8}", rnd.Next(1000, 10001));
  20.          if (ctr % 5 == 0) Console.WriteLine();
  21.       }
  22.  
  23.       Console.WriteLine("\n20 random integers from 1 to 10:");
  24.       for (int ctr = 1; ctr <= 20; ctr++)
  25.       {
  26.          Console.Write("{0,6}", rnd.Next(1, 11));
  27.          if (ctr % 5 == 0) Console.WriteLine();
  28.       }
  29.    }
  30. }