Solved

C# Random Numbers

Posted on 2012-04-06
2
572 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

The CRUD Functions CRUD, meaning "Create, Read, Update, Delete (http://en.wikipedia.org/wiki/Create,_read,_update_and_delete)" is a common term to data base developers.  It describes the essential functions of data base table maintenance.  This art…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

790 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