Solved

C# Random Numbers

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now