C# Random Numbers

How do I use/call  new Random() or ranNumberGenerator in a decision structure in a console application?

Random ranNumberGenerator = new Random() ; // Instantiate random number generator
int randomNumber;
randomNumber = ranNumberGenerator. Next(3) ;  // generate a number between 0 and 2

I need there to be three possible choices for the generator r, p, c. If the user selects r and if the random generator picks p then the generator wins ect. Need an example of the structure
Who is Participating?
Miguel OzConnect With a Mentor Software EngineerCommented:
assuming that p=r+1 c=p+1 then
r =  MIN_VALUE ;
where MIN_VALUE is constant defined by your app..

I ma not sure what you mean about decision structure, but your logic should be
private void ProcessAnswer(int userAnswer)
 randomNumber =MIN_VALUE  + ranNumberGenerator. Next(3) ;    
 if (userAnswer == randomNumber)
   Console.Write("User wins");
   Console.Write("User loses");
December2000Author Commented:
Thank you!

How do  I declare the r, p, c? int r, int p, int c ?
For user input do I use Console. ReadLine() ; ? If so where do I use it?
Random ranNumberGenerator = new Random(); // Instantiate random number generator
int randomNumber;
int numberString;
//int= number
randomNumber = ranNumberGenerator. Next(4);  // generate a number between 0 and 2
      Console. Write(" Enter  r, p, or c " );
      numberString= Console.ReadLine();
      number = Convert. ToInt32 (numberString) ;

logic here?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.