Solved

C# Random Numbers

Posted on 2012-04-06
2
571 Views
Last Modified: 2012-04-07
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
0
Comment
Question by:December2000
2 Comments
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 37817749
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");
 else
   Console.Write("User loses");
}
0
 

Author Comment

by:December2000
ID: 37817805
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?
}
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"Disruption" is the most feared word for C-level executives these days. They agonize over their industry being disturbed by another player - most likely by startups.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question