Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random Number Generation 1

Status
Not open for further replies.

hisheeraz

Programmer
Mar 24, 2003
28
AU
Hello
I have this code that is not working and giving me compile error...im using visual studio .net 2005

Code:
using System;

namespace RandomNumberGenerator
{
    /// <summary>
    /// Random Number Generator 
    /// Author: Sheeraz AHMED
    /// DAte: 25-05-2007
    /// </summary>
    class Random
    {
        static void Main(string[] args)
        {
            Random ran = new Random();

            Console.WriteLine(ran.Next (1, 7)); 

            Console.Write("\n\nPlease press enter to quit");
            Console.ReadLine();

        }// end main
    }//end random class 
}// end random number generator namespace

im getting error at this line

Code:
            Console.WriteLine(ran.Next (1, 7));

and here is the error that i am getting

Code:
Error	1	'RandomNumberGenerator.Random' does not contain a definition for 'Next'	D:\My .NET Work\C #\Console\RandomNumberGenerator\RandomNumberGenerator\Random.cs	16	35	RandomNumberGenerator

could any one please tell me what is wrong with the code?

thanks

§ Rented Lips §
----------------
Begning To Learn
----------------
 
it's a naming conflict. Your Class named Random interfers with System.Random.
2 options rename your class. or alias the System namespace.
Code:
using System;
namespace RandomNumberGenerator
{
   public calss MyRandom()
   {
      function GetRandomNumber()
      {
         Random rand = new Random();
         rand.Next();
      }
   }
}
or
Code:
using S = System;
namespace RandomNumberGenerator
{
   public calss Random()
   {
      S.Random rand = new S.Random();
      rand.Next();
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
excillent help
thank you

§ Rented Lips §
----------------
Begning To Learn
----------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top