Statistical and math code/functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Clarkent
Forum Newbie
Posts: 6
Joined: Sat Jan 01, 2005 8:29 am

Statistical and math code/functions

Post by Clarkent »

Anyone know some code and/or function to implement math systems on lottery and/or number extractions ?
E. g. National lottery that extract 6 numbers ... there are a lot of number combinations ... but if I use some math systems (like linear progression ... etc.) I can reduce combinations ... or if I insert some variable restictions (e. g. not considerer all sequential numbers extractions like for example 1,2,3,4,5,6 ... that very difficult to extract) i can to reduce number of combinations, ecc.
I ask if anyone know some script or function, or class o other tool usefull fo this job. PHP of course ...

Thanks
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

I don't actually understand your question, but I will point out that a number sequence such as 1,2,3,4,5,6 is just as likely to come up in the lottery as any other group of 6 numbers.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

function pickSome( $howMany, $numbers )
{
  $final = $numbers;
  $howMany = abs(intval($howMany));
  if( !is_array($final)) $final = array();
  shuffle($final);
  return array_slice($final, 0, $howMany);
}
Clarkent
Forum Newbie
Posts: 6
Joined: Sat Jan 01, 2005 8:29 am

Of course

Post by Clarkent »

Yes ... 123456 are the same probability of any other combination. But I'm looking for a system that allow to define criterials to reduce combinations number.
For that i'm looking fo a math/statistical implementation (in PHP) that allows to insert (for example) 30 numbers and to calculate all combinations of 6 numbers of these 30 numbers. At the same time I should got a system that allows to insert also restriction criterial (for example: calculate all number combination except the combinations that contain more than 4 sequenzial numbers ... for example 34, 45,46,47,48,49).
The restriction criterials are based on a teorical difficulty to extract weird combinations (for example 1,2,3,4,5,6 or, example above, 34,45,46,47,48,49) ...
My english is very very terrible .... sorry

Thanks
Clarkent
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Re: Of course

Post by timvw »

Clarkent wrote:Yes ... 123456 are the same probability of any other combination. But I'm looking for a system that allow to define criterials to reduce combinations number.
For that i'm looking fo a math/statistical implementation (in PHP) that allows to insert (for example) 30 numbers and to calculate all combinations of 6 numbers of these 30 numbers.
With recursion you can write it quite easily yourself. Although i'm not going to do your homework, but i'll give you a sample (in euler)

Code: Select all

function buildcombo(V)
if (cols(V) == 1);
  return Vї1];
endif;

Combo = zeros(0, 0);

for i = 1 to cols(V);
  nV = Vї1:i-1] | Vїi+1:cols(V)];
  SCombo = buildcombo(nV);
  for j = 1 to rows(SCombo);
    Combo = Combo _ (Vїi] | SComboїj]);
  end;
endif;

return Combo;
endfunction
Clarkent wrote: At the same time I should got a system that allows to insert also restriction criterial (for example: calculate all number combination except the combinations that contain more than 4 sequenzial numbers ... for example 34, 45,46,47,48,49).
The restriction criterials are based on a teorical difficulty to extract weird combinations (for example 1,2,3,4,5,6 or, example above, 34,45,46,47,48,49) ...

So first you build all the possible combinations, and then you test each combination and (eventually) push it to the valid_combinations ...
Clarkent
Forum Newbie
Posts: 6
Joined: Sat Jan 01, 2005 8:29 am

Thanks

Post by Clarkent »

Thank you for your helpfulness ... is correct ? Anyway thank you ...
Post Reply