Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i confuse about class.. how to construct this code to class? in C#console appli
C#
static void Main(string[] args)
{

Random generator = new Random();
int Random = generator.Next(1032, 2353);

Console.WriteLine(Random);
}
}



---------------------------------------------
C#
static void Main(string[] args)
{
          Console.WriteLine("RandomCode:");
          string code = string.Intern (Console.ReadLine());

          Random generator = new Random();
          generator.Code = code;
}


//my class

class Random
{
    public Random() { }


    private string code;
    public string Code
    {
        get { return code; }
        set { code = value; }
    }

}

I dont know how to put this to a class.
C#
Random generator = new Random();
int Random = generator.Next(1032, 2353);

Console.WriteLine(Random);

-------
Posted
Updated 4-Mar-14 0:34am
v5
Comments
Maciej Los 4-Mar-14 5:26am    
What?
OriginalGriff 4-Mar-14 5:34am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
jone,jake 4-Mar-14 5:43am    
KEYBOARD PROBLEM SIR...SORRY.
OriginalGriff 4-Mar-14 5:55am    
AND AGAIN?
Yeah, I believe you...
jone,jake 4-Mar-14 6:05am    
help me with my code sir,..:)
im just 3yr. high school..

1 solution

C#
using System;

public static class Randomizer
   {
       private static Random RND
       {
           get { return _rnd ?? (_rnd = new Random()); }
       }
       private static Random _rnd ;

       public static int GetNext()
       {
           return RND.Next();
       }

       public static int GetNext(int max)
       {
           return RND.Next(max);
       }

       public static int GetNext(int min, int max)
       {
           return RND.Next(min, max);
       }
   }

   class Program
   {
       static void Main(string[] args)
       {
           Console.WriteLine("Next random is: {0}", Randomizer.GetNext(1032, 2353));
           Console.WriteLine("Next random is: {0}", Randomizer.GetNext(1032, 2353));
           Console.WriteLine("Next random is: {0}", Randomizer.GetNext(1032, 2353));
           Console.ReadKey();
           return;
 
Share this answer
 
v2
Comments
jone,jake 4-Mar-14 6:32am    
the type or namespace 'Random' could not be found(are you missing a using directive or an assembly....

what is missing???
Thomas Nielsen - getCore 4-Mar-14 8:40am    
using System;

i've added my usings to an updated solution
jone,jake 4-Mar-14 9:31am    
i get it..tnx:)
jone,jake 4-Mar-14 9:42am    
how about using loop sir?
random number using for loop?
Thomas Nielsen - getCore 5-Mar-14 5:31am    
i am unsure what you want to loop, forever? a random number of times?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900