Solved

C# Random Numbers

Posted on 2012-04-06
2
573 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 36

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
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
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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