# Random Numbers question

Page 1 of 1

## 6 Replies - 3551 Views - Last Post: 05 December 2010 - 09:02 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=203851&amp;s=4aba363c617062ee5f29877c3b69729f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 millertime03

Reputation: 0
• Posts: 4
• Joined: 29-November 10

# Random Numbers question

Posted 05 December 2010 - 07:53 PM

The problem statement is to develop a lottery function that will draw numbered balls from 1 to 10. Assume that 3 balls are drawn at random. Allow the user to enter the number of lottery drawings to simulate. Calculate and print the percentage of the time the result contain 3 even numbers in the simulation. Also calculate and print the time 7 occur in the three numbers in the simulation.

I have the following code and i can get it to generate the correct amount of sets the user inputs, but i can not get it to just put 3 numbers in each set. it wil give and answer similar to 345, 2345, 1234, 224 and 2345, for a user input of 5. but i need just 3 numbers per set. Any advice would be appreciated.

Thanks Miller.

```void Lottery(int x)
{
int random_integer, user_input, lowest=1, highest=10, range=(highest-lowest)+1;
cout << "How many times would you like me to simulate the lottery drawing:  ";
cin >> user_input;

for (int index = 0; index < user_input; index++)
{
random_integer = lowest + int (range*rand());
(RAND_MAX +1);
cout << random_integer << endl;
}

/*cout << "                              Operations \n " << endl;
cout << "1. Temperature Conversion Celsius to Fahrenheit" << endl;
cout << "2. Salary Calculator" << endl;
cout << "3. Print A Hollow Square" << endl;
cout << "4. Estimate The Value Of Pi" << endl;
cout << "5. Lottery Drawing" << endl;
cout << "6. Exit Program \n\n" << endl;

cin >> program; */
return;
}
```

This post has been edited by NickDMax: 05 December 2010 - 10:30 PM
Reason for edit:: added code tags: [code] -- paste your code here -- [/code]

Is This A Good Question/Topic? 0

## Replies To: Random Numbers question

### #2 #define

• Duke of Err

Reputation: 1853
• Posts: 6,671
• Joined: 19-February 09

## Re: Random Numbers question

Posted 05 December 2010 - 08:12 PM

Here is another way of Producing Random Numbers for you to look at.

### #3 CTphpnwb

• D.I.C Lover

Reputation: 3778
• Posts: 13,690
• Joined: 08-August 08

## Re: Random Numbers question

Posted 05 December 2010 - 08:18 PM

First, use code tags!!!

Second, the code you show will output N random numbers where N is supplied by the user. My guess is that you want to return numbers perhaps in a two dimensional array with three random numbers selected N times, but that's impossible to know given the limited information you've provided.

### #4 millertime03

Reputation: 0
• Posts: 4
• Joined: 29-November 10

## Re: Random Numbers question

Posted 05 December 2010 - 08:39 PM

CTphpnwb, on 05 December 2010 - 07:18 PM, said:

First, use code tags!!!

Second, the code you show will output N random numbers where N is supplied by the user. My guess is that you want to return numbers perhaps in a two dimensional array with three random numbers selected N times, but that's impossible to know given the limited information you've provided.

Ok This is my first semester of this so not to sound stupid but what do you mean by code tags? I also don't have any other info to give you because this is all he gave me. Our teacher has also not told us about how to do arrays. Thanks

### #5 millertime03

Reputation: 0
• Posts: 4
• Joined: 29-November 10

## Re: Random Numbers question

Posted 05 December 2010 - 08:45 PM

If you need to know something else or have a question just ask I dont mind answering it to the best of my knowledge.

### #6 CTphpnwb

• D.I.C Lover

Reputation: 3778
• Posts: 13,690
• Joined: 08-August 08

## Re: Random Numbers question

Posted 05 December 2010 - 08:52 PM

```[code ]code tags allow code to retain indenting and some highlighting![/code ]
```

If you aren't going to use arrays, the you'll want to output three random numbers each time you go through the loop instead of one.

### #7 millertime03

Reputation: 0
• Posts: 4
• Joined: 29-November 10

## Re: Random Numbers question

Posted 05 December 2010 - 09:02 PM

Oh ok gotcha. ok I'll give it another try tomorrow thanks.