A random number within a specified range. : Random « Development Class « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# Book
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Development Class » RandomScreenshots 
A random number within a specified range.
 

using System;

public class Example
{
   public static void Main()
   {
      Random rnd = new Random();

      Console.WriteLine("20 random integers from -100 to 100:");
      for (int i = 1; i <= 20; i++
      {
         Console.Write(rnd.Next(-100101));
      }

      Console.WriteLine("\n20 random integers from 1000 to 10000:");      
      for (int i = 1; i <= 20; i++
      {
         Console.Write("{0,8}", rnd.Next(100010001));
      }

      Console.WriteLine("\n20 random integers from 1 to 10:");
      for (int i = 1; i <= 20; i++
      {
         Console.Write("{0,6}", rnd.Next(111));
      }
   }
}

   
  
Related examples in the same category
1.Get Random number
2.Shifted and scaled random integers.
3.Roll a six-sided die 6000 times.
4.Get next random number in doubleGet next random number in double
5.An automated pair of diceAn automated pair of dice
6.Random Color and Rectangle
7.Example of the Random class constructors and Random.NextDouble( ) method.
8.Next bytes
9.Generate and display 5 random integers.
10.Generate and display 5 random integers between 0 and 100.
11.Generate and display 5 random integers from 50 to 100.
12.Generate and display 5 random floating point values from 0 to 1.
13.Generate and display 5 random floating point values from 0 to 5.
14.Returns a nonnegative random number less than the specified maximum.
ww__w.___ja_v___a2s.c___o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.