#!perl
#
# $Id: lotto6,v 1.3 1991/12/09 22:36:48 wengland Exp $
#
# $Log: lotto6,v $
# Revision 1.3  1991/12/09  22:36:48  wengland
# Modified terminology to match WSL terms and descriptions.
# Added better statistics collection and a standard deviation
# of percent selected to provied usefull distribution information.
#
# Revision 1.2  1991/12/07  06:36:30  wengland
# Set it up to print out initial auto randomization key.
# Print date and moved cost information around.
#
#
eval "exec perl -S $0 $*"
	if $running_under_some_shell;

## Random Washington State Loto pannel drawing program.
##

##
 #  (c) Copyright 1991, Stephen Software Systems, Inc.
 #
 #  This software is furnished under the terms of the GNU
 #  public license and is freely distributable.
 #
 #  Using this software will in no way change your odds of 
 #  winning the Washington State Loto or any other game 
 #  of chance.
 #
 #  This software is supplied FREE of charge and comes with
 #  no warrenties expressed or implied.  The author is not
 #  responsible for any damages, monetary or otherwise.
 #
 #               USE AT YOUR OWN RISK.
##

 ## The following number is system dependant.  You must change it
  # to match the bit size of your systems random number generator.
  #
  # (Actually it only needs to be on the same scale  a minor error
  #   will not make a differance.)
  # 
  #   8 bit, 2^7 -1  or 127
  #  16 bit, 2^15 -1 or 32,767
  #  32 bit, 2^31 -1 or 2,147,483,647
  #
 $rand_mod = 2147483647;
  ##
   # IT should be noted however that a random number generator
   # with a Modulus of less than 14M will result in a quite
   # non random selection.  The only way to fix this is by
   # building your perl package with a 'good' random number
   # generator built into it.
   #
   # However your odds are still so low that you really 
   # don't need to worry about it.  :-)
  ##

## Parameters. 
 # -k Random number key to start with. (Pick your favorite lucky number.
 #     or the prior output of this program labled Next Key:  )
 #    (default, something really wierd and not predictable)
 # -g number of groups to select. (default 1)
 # -n number of numbers per group. (default 10.)
 # -p number of pannels per group. (default 10, one $5 pannel.)
 #

require "getopts.pl";
    if (!&Getopts('k:g:p:n:')){
     print "\nThe following options are available:\n\n".
  "    -k Random number key to start with. (Pick your favorite lucky number.\n".
  "        or the prior output of this program labled Next Key:  )\n".
  "       (default, something really wierd and not too predictable)\n".
  "    -g number of groups to select. (default 1)\n".
  "    -n number of numbers per group. (default 10.)\n".
  "    -p number of pannels per group. (default 10, one $5 pannel.)\n"; 
	exit;
    }

    print `date`;

    if ($opt_k){
	print "User defined key=$opt_k\n\n";
	srand($opt_k);
    } else {
	## Pick a fairly random seed based very on 
	 # the time of day.
	&randomize();
    }

    if ($opt_g){
    }else{
       $opt_g = 1;
    }
    if ($opt_p){
    }else{
       $opt_p = 10;
    }
    if ($opt_n){
    }else{
       $opt_n = 10;
    }

   printf("%s Groups, %s Numbers per Group, %s Pannels per Group\n",
		$opt_g, $opt_n, $opt_p );

   printf( "Cost per group: \$%.2f. Cost of all groups: \$%.2f \n\n", 
       $opt_p * .5, $opt_p * .5 * $opt_g);

## This program uses a group method of selecting
 # lotto pannel.  First 10 numbers are selected 
 # from the 40 available,  then  5 combinations of
 # the 10 numbers are chosen.
 #
 # The idea is that it is a lot more likely to pick
 # 10 possible numbers than to pick only 6 and 
 # chosing combinations of the 10 gives an illusion
 # that you are somehow more likely to win. 
 #
 # The odds are unchanged of course and your chances 
 # of winning are still 14M to one.
 #

    ## Number of members in group must be greator than
     # 6 and less than 50.
     #
    if ($opt_n <7 || $opt_n > 49){
	print STDERR 
	"Number of members in group must be greator than 6 and less than 50.\n";
       exit 1;
   }

    ## Initialize.
     #
    @selection=split(/ /,"01 02 03 04 05 06 07 08 09 10 ".
			"11 12 13 14 15 16 17 18 19 20 ".
			"21 22 23 24 25 26 27 28 29 30 ".
			"31 32 33 34 35 36 37 38 39 40 ".
			"41 42 43 44 45 46 47 48 49" );

    %Group=();
    while( (@ttl_Groups=keys(%Group)) < $opt_g ){
	## Draw one number at random and put it in line of group.
	 #
	@r_group=();
	while( @selection ){
	    push (@r_group, splice(@selection, rand @selection, 1 ));
	}
	@selection = @r_group;
	@r_group = ();

	$ctr = $opt_n;  # Total numbers in group.
	while( $ctr--){
	    $r_group[$ctr$ctr = $opt_n;  # Total numbers     ## In5_p nlectr = $o join(" "y wiur 
	$ctr =();
    w
    Che# cmonedu ran$opr st     
	wh $o(_k\n\n";$){
	{ectr =}r_grou  , %s NumD = Gt of aoupopt_p *$ctr =();          n  ";ctr$ctr} .5, $opt_){
	{ectr =}r= join(" "y 
	$ctr =();$opt_g){
       Pauto randf \n\n", electionn=split(cmoneaf yectr = ( wiur(opt_while(  \nThe 	&do_a$ctr =( 03 04 05 0t_){
	{ectr =}) ();$opt_g){
   ed key=
  "      "y  ke(  } el3647;
 )), opt";opyright 1yrightsub do_a$ctr == 10;
loor(@selecti)gro_; 10;
loor(    ,    1); 10;
loor(hile( _tions,@tionelecti)gpt_ g){
   ed keNumGt of aoupop"y join(" "y wiur 
	$ctr =(();
    wmoneaf yectr =_must b( 
	$ctr =({ .5, $opt_){
	_tions{ectr =_must b}r= 0 Initializeze.
    dom see numberlection=split(%\n",
  $opt_n;lit(/D =_\n",
(@ttl_Groups=keys(%Grou\n",
(opt_g \n",
## Draw onpr_gro

	$ogram.lection ){
		$ctr = _group, splice(@seogram.on, rand @selection1 ));selectionction = @r_gr   $ctr = $o@seogram.;

	$ogram.lopt_n;  # Total 6s in group.
	while( $ numberle
	    $r_group[$ctr$ctr =  numben;  # Tota= $opt_n;  # n = @r_g .5, $opt_ogram.lo join(" "y wiur 
	$ogram.();
    w
    Che# cmonedu ran$opr st     
	wh $o(_k\n\n";$\n",
{_ogram.}r_grou ,lic(/D =_\n",
,t_ogram.();            n  ";ctr$ctr} .
    w
    Ctandareator ttion n and  st        
	w   w
 moneaf yectr =_must b( 
	$ogram.[$ctr$ct_){
	_tions{ectr =_must b}++
   }

} .
    w
 $\n",
{_ogram.}r= 0 Initiialize.
     Pauto orcultherator ttion and arlection=split(moneaf yectr =_must b( wiur(opt_while( _tions )({ .5, $opt,lic( @tionelecti, ctr$cts, %s Numb2s"y  ke(_){
	_tions{ectr =_must b}/lse{
 *6)*100)tion =itiialize.
    Crcultherne of auto  arlection=split(in slo  E(x-x')^2split(in     ---- n-1 ----split(i$xxr= 0 Initii(moneaf yectr =_tion( @tionelecti){ ctr$$xxr+=yectr =_tion;* .5, $o}split(i$xxr/= @tionelectis in Crculthermeaea isplit(i$sr= 0 Initii(moneaf yectr =_tion( @tionelecti ){ ctr$loor( a,t_b)lop0,0();    $a =yectr =_tion -i$xx);        $sr+=yea*$a; .5, $o}spsplit(i$sr/= ($#tionelecti)s in Crculthers.g){
   ed keNum Gstt aoup sd=    op"y join(" "y @tionelecti)y wqur($s(();
 {
       Pauto f \nD =  numberlectionn=split(cmoneaf yedu $ogram.( wiur 
D =_\n",
 ({ .5, $opt  ed keNum nD = aoupop"y edu $ogram.on =itiialize{
       Pauto randf \nten  numberlectionn=split(cmoneaf yeogram.( wiur(opt_wh\n",
 ( 
	"NumbeNum n  P aoupop"y eogram.[($opt_n){
   owing opt";op}yright 1yrightsub  }

    { .5, $andom= (andom% 100)*10000 Initi   } elando[($opt_loor(  ycle)lo ke(  } e1000(();
       W Th  e
 #
dos collerlectio=split  } e)ups=ke   ycle-- > 0 InIniti   } el yclelo  } el3647;
 ));roups, %s NumA key.
# Print date a=%sopt
