How to calculate lottery combinations by sums part 2

shadowfighter666

New Member
Joined
Jan 23, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello everyone:


The link above has a working formula for me to use for VBA, but I cannot use it for 80 lottery numbers that draw 20 numbers per draw. It errors out to an Overflow. Please assist, many thanks!

I believe it has to do with the variables declare as Long, but I am not sure how to change it to make it work.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I think that you will find that such a large pool will be beyond the capabilities of excel, and most likely any computer that had less than 9 digits on the price tag.

The code was written for a draw of 6 from 49, which is 13,983,816 possible combinations.

For your requirement there would be circa 3,535,316,142,212,180,000 possible combinations, that is a ludicrous amount of data to try and process.
 
Upvote 0
There's no need to ratchet through all the combinations and sum the results to calculate the histogram of sums; it can be calculated in closed form with a generating function (see thread). However, a Double data type runs out of resolution at 2^53 (about 9,007,199,254,740,990). A Double can store much larger numbers, of course, but not with a resolution of 1.

The number of ways to get to the sum 714 with 20 numbers selected from the set 1 to 80 is 8,933,096,352,127,630, right up at the edge. Beyond that, adding loses precision. The peak is the sum 810, for which there are (about) 15,542,763,534,960,600 ways to arrive.

I reckon the function could be modified to use Decimal data types, but it would be way, way slower than the 10s or so it takes to calculate combinations of 80, or the eye blink it takes for combinations of 49.
 
Last edited:
Upvote 0
Double data type runs out of resolution at 2^53 (about 19,007,199,254,740,990)

Minor typos: 2^53 is 9,007,199,254,740,992.

Excel actually calculates 2^53 exactly, but it only formats up to 15 significant digits (rounded). That is why we see 9,007,199,254,740,99
0.

(Note that =SUM(2^53,-(2^53&"")) returns 2.)
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,421
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top