lottery numbers

S

styfir

Hi I'm new here so I was wondering if someone could help me out with
writing a proggy in C++ to display 6 lottery numbers (1-49). Now
these numbers would have to be generated randomly then compared to each
other to see that they're all different, because you dont get repeated
numbers in the actual lottery!!

After that is done I'd like to store these in an array and create
another array for another set of 6 lottery numbers. Comparing one set
to another set so they are uniquely different!

The aim here is to see how many combinations of 6 numbers you can get
using numbers from 1-49 !!!

I know its going to be massive but my curiosity is killing me!!

ANYONE HELP???

the styf
 
V

Victor Bazarov

styfir said:
Hi I'm new here so I was wondering if someone could help me out with
writing a proggy in C++ to display 6 lottery numbers (1-49). Now
these numbers would have to be generated randomly then compared to
each other to see that they're all different, because you dont get
repeated numbers in the actual lottery!!

After that is done I'd like to store these in an array and create
another array for another set of 6 lottery numbers. Comparing one set
to another set so they are uniquely different!

The aim here is to see how many combinations of 6 numbers you can get
using numbers from 1-49 !!!

I know its going to be massive but my curiosity is killing me!!

ANYONE HELP???

We'll help you out, sure. But we're not going to write it for you.
You do the coding, and if/when you encounter a problem you cannot solve,
post your questions. Read the Welcome message and the FAQ before your
next post, please.

V
 
M

Markus Schoder

styfir said:
Hi I'm new here so I was wondering if someone could help me out with
writing a proggy in C++ to display 6 lottery numbers (1-49). Now
these numbers would have to be generated randomly then compared to each
other to see that they're all different, because you dont get repeated
numbers in the actual lottery!!

After that is done I'd like to store these in an array and create
another array for another set of 6 lottery numbers. Comparing one set
to another set so they are uniquely different!

The aim here is to see how many combinations of 6 numbers you can get
using numbers from 1-49 !!!

I know its going to be massive but my curiosity is killing me!!

That can be helped. The number is

49! / ((49-6)! * 6!) = 13983816
 
O

osmium

styfir said:
Hi I'm new here so I was wondering if someone could help me out with
writing a proggy in C++ to display 6 lottery numbers (1-49). Now
these numbers would have to be generated randomly then compared to each
other to see that they're all different, because you dont get repeated
numbers in the actual lottery!!

After that is done I'd like to store these in an array and create
another array for another set of 6 lottery numbers. Comparing one set
to another set so they are uniquely different!

The aim here is to see how many combinations of 6 numbers you can get
using numbers from 1-49 !!!

I'm afraid you are going to die of old age before you get an answer to your
question by this method.
Use math to get some idea of what the answer might be. Then assume you can
get a million answers a second. Then compute your expected lifetime in
seconds. Do you see a problem?
 
M

Marcus Kwok

styfir said:
Hi I'm new here so I was wondering if someone could help me out with
writing a proggy in C++ to display 6 lottery numbers (1-49). Now
these numbers would have to be generated randomly then compared to each
other to see that they're all different, because you dont get repeated
numbers in the actual lottery!!

After that is done I'd like to store these in an array and create
another array for another set of 6 lottery numbers. Comparing one set
to another set so they are uniquely different!

The aim here is to see how many combinations of 6 numbers you can get
using numbers from 1-49 !!!

You do not need to write a program to find this out. You can calculate
it directly using the "number of combinations" formula:

x C y (pronounced "x choose y", not sure if this is the standard
noation for it) gives you the number of combinations of y elements
when there are x things to choose from, when order doesn't matter.
This differs from the number of permutations, where order does
matter. The Standard Library has a function to generate
permuations, but AFAIK not for combinations.

x C y = (x!) / ((x-y)!y!) // You will want to look this up to verify

where ! is the factorial operator. So you want to calculate (49 C 6).
Look in a Combinatorics textbook for more information.
 
D

Dennis Jones

styfir said:
Hi I'm new here so I was wondering if someone could help me out with
writing a proggy in C++ to display 6 lottery numbers (1-49). Now
these numbers would have to be generated randomly then compared to each
other to see that they're all different, because you dont get repeated
numbers in the actual lottery!!

After that is done I'd like to store these in an array and create
another array for another set of 6 lottery numbers. Comparing one set
to another set so they are uniquely different!

The aim here is to see how many combinations of 6 numbers you can get
using numbers from 1-49 !!!

A couple of insights might be helpful here:

1) Using random numbers, you'll *never* (probably never) compute the number
of unique combinations, because you'll very likely get the same set(s) many,
many times, over and over and over again (ouch!) and you'd still have to
compare them to your existing sets every single time (to see if it is a
duplicate of an existing set). There is no way to predict how long this
would take, but I can guarantee that it would be a very long time!

2) If you don't mind using brute force (which it sounds like you don't!),
you could simply use 6 nested loops (one for each number), making sure that
each loop only iterates over numbers that are not in one of the previous
loops. Count the number of times the inner-most loop executes, and you'll
have the total number of combinations. This will still take a while (maybe
0.1 second on a fast PC). Not very long in the grand scheme of things, but
certainly not very efficient.

3) The best solution is to use the combination formula from statistics:
n!/r!(n-r)!

- Dennis
 
T

Tomás

styfir posted:
Hi I'm new here so I was wondering if someone could help me out with
writing a proggy in C++ to display 6 lottery numbers (1-49). Now
these numbers would have to be generated randomly then compared to each
other to see that they're all different, because you dont get repeated
numbers in the actual lottery!!

I wouldn't go that route, because, in theory, the algorithm may run
indefinitely. (I know it won't in practise, but bear with me).

Here's a route that might work:


int numbers_available[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10,
11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49 };


Then make a "Number Basket" class as follows:

class NumberBasket
{
protected:
int* p_numbers;

unsigned amount_available;

public:

NumberBasket( int* const arg_p, unsigned const arg_amount )
: p_numbers(arg_p), amount_available(arg_amount) {}


int PickNumber( unsigned index )
{
if ( index > (amount_available - 1) ) throw (-1);

int number = p_numbers[index];

p_numbers[index] = p_numbers[amount_available - 1];

--amount_available;

return number;
}
};


Example:

If number thirteen gets taken out, then 49 gets put in its place as follows:

1,2,3,4,5,6,7,8,9,10,11,12,49,14,15,16,17....

but the "amount_available" has one less so it'll only go up as far as 48.

This removes the chance of the algorithm running forever.


-Tomás


Then I would probably use a class as follows:

template<int i>
unsigned char PickNumber( unsigned char (&numbers_available) )
{
return PickNumber_X( numbers_available );
}

template<class T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top