Re: Lotto 7/45



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
.



Relevant Pages

  • Re: Project help
    ... Low Power AES algorithm using VHDL ... in GALIOS FIELD and other parts of the algorithm like galios field ...   port( ...
    (comp.lang.vhdl)
  • Re: Lockfree flqueue and lockfree_mpmc ...
    ... and they all have the same problem under contention, ... MOV ECX, EAX ... there is a problem with this algorithm on the push and pop side... ...   then ...
    (comp.programming.threads)
  • Re: Project help
    ... Low Power AES algorithm using VHDL ... in GALIOS FIELD and other parts of the algorithm like galios field ...   port( ...
    (comp.lang.vhdl)
  • Re: Congruence based factoring algorithm
    ... algorithm will run faster with as small a p as possible; ...    report that T is prime ... Can you prove an upper bound on the numbers for which the effect can ... so it's equivalent to a brute force technique as a k that works gives ...
    (comp.theory)
  • Re: Godel proved maths inconsistent not incompleteness theorem
    ... | equals that line. ... |   a. ... your algorithm doesn't show that, for each line of the proof, ... It's not even a proof verifier for valid proofs. ...
    (sci.logic)