Re: Lotto 7/45
- From: amzoti <amzoti@xxxxxxxxx>
- Date: Wed, 6 Aug 2008 08:33:39 -0700 (PDT)
On Aug 6, 1:29 am, TheOne <daewon.y...@xxxxxxxxx> wrote:
In Korea, the lotto is 7/45.
I found an algorithm to generate a random case, it looks like :
for(i=0 ; i<7; i++)
{
n = random()%45;
if(already_chosen(n))
{
i--;
continue;
}
choose(n);
}
I found it ineffective. random() function is called 7 times or more.
random() can choose among 0 ~ MAX_RAND ( = 0x7FFF = 2^15 - 1 ).
The number of total possible cases for korean lotto is
(45*...*39)/(1*..*7) = 0x2b4,7024 < 0x400,0000 = 2^26.
Therefore there should be an algorithm that 3 times of random()
function call suffice to generate a random case, because 26 is
less than 15*3, equivalently because 2^26 is less then (2^15)^3 .
Only I can't thnik of a simple algorithm for that.
I want an algorithm by which a 27 bit random integer suffice to make a
case.
Have any idea?
TIA.
Follow-up to : comp.programming
--
Daewon YOON
Perhaps this will help?
http://c-faq.com/lib/randrange.html
All you would do is call the function n-times until it returns 7
numbers in the range of 1-45 without repeats - and you already have an
algorithm for that.
Of course none of this will help you win the lottery!
If you need more bits than are supplied by the RAND_MAX, you'll have
to look at some multiple precision math library - like GMP or
libtommath or MIRACL or other.
Also, you might want to consider a CAS (see:
http://en.wikipedia.org/wiki/List_of_computer_algebra_systems), which
all contain large integer math and rand routines.
HTH ~W
.
- Prev by Date: Re: Lotto 7/45
- Next by Date: Re: Lotto 7/45
- Previous by thread: Re: Lotto 7/45
- Next by thread: Re: Lotto 7/45
- Index(es):
Relevant Pages
|