• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

RANDBETWEEN-Creating a Lottery Engine

Dear Forum Members,

I want to create a lottery engine using RANDBETWEEN. I will click on a command button and get a new lottery number within 1001 to 1500 every time. We will have to consider.......

1. Ticket serial from 1001 to 1500

2. 20 gifts will be given

3. No duplicate lottery number will be come


Regards,


Muneer
 
This would be my approach:


In VBA:

(1) load the values 1001 to 1500 into an array

(2) shuffle the array into a random order using a Fisher-Yates shuffle

(3) pick the first 20 elements from the array


This ensures an efficient, yet truly random, selection of non-duplicated numbers. There's a VBA fisher yates shuffle algorithm here:

http://colinlegg.wordpress.com/2012/07/02/shuffling-an-array-in-vba/
 
@nazmul_muneer

Hi!

In the posted link there's an example of shuffling an array, so for a whole example for this topic it's only necessary to retrieve the first 20 values, as Colin Legg correctly posted. Is there anything missing?

Regards!
 
Back
Top