Lotto Generator

By Red-Dwarf on Jan 09, 2009

This script generates numbers to use in your next lotto draw. In my country we have a 7th 'Bonus Ball' which I have included. To remove it, simly delete the %num7 lines. Also, if you have a lucky number that you wish to incorporate, type !lottolucky . Enjoy!

Disclaimer: I cannot guarantee that you will win the lotto using this script.

Alias lottonum {
  %num1 = $rand(1,49)
  :tryagainA
  %num2 = $rand(1,49)
  if %num2 = %num1 { /goto tryagainA }
  :tryagainB
  %num3 = $rand(1,49)
  if %num3 = %num2 || %num3 = %num1 { /goto tryagainB }
  :tryagainC
  %num4 = $rand(1,49)
  if %num4 = %num3 || %num4 = %num2 || %num4 = %num1 { /goto tryagainC }
  :tryagainD
  %num5 = $rand(1,49)
  if %num5 = %num4 || %num5 = %num3 || %num5 = %num2 || %num5 = %num1 { /goto tryagainD }
  :tryagainE
  %num6 = $rand(1,49)
  if %num6 = %num5 || %num6 = %num4 || %num6 = %num3 || %num6 = %num2 || %num6 = %num1 { /goto tryagainE }
  :tryagainF
  %num7 = $rand(1,49)
  if %num7 = %num6 || %num7 = %num5 || %num7 = %num4 || %num7 = %num3 || %num7 = %num2 || %num7 = %num1 { /goto tryagainF }
  %chan = $readini($mircdir\lotto.ini, lotto, chan)
  msg %chan Your lucky numbers are:4 %num1 %num2 %num3 %num4 %num5 %num6 ( $+ %num7 $+ )
}

Alias lottonum2 {
  %num1 = $readini($mircdir\lotto.ini, lotto, lucky)
  :tryagainA
  %num2 = $rand(1,49)
  if %num2 = %num1 { /goto tryagainA }
  :tryagainB
  %num3 = $rand(1,49)
  if %num3 = %num2 || %num3 = %num1 { /goto tryagainB }
  :tryagainC
  %num4 = $rand(1,49)
  if %num4 = %num3 || %num4 = %num2 || %num4 = %num1 { /goto tryagainC }
  :tryagainD
  %num5 = $rand(1,49)
  if %num5 = %num4 || %num5 = %num3 || %num5 = %num2 || %num5 = %num1 { /goto tryagainD }
  :tryagainE
  %num6 = $rand(1,49)
  if %num6 = %num5 || %num6 = %num4 || %num6 = %num3 || %num6 = %num2 || %num6 = %num1 { /goto tryagainE }
  :tryagainF
  %num7 = $rand(1,49)
  if %num7 = %num6 || %num7 = %num5 || %num7 = %num4 || %num7 = %num3 || %num7 = %num2 || %num7 = %num1 { /goto tryagainF }
  %chan = $readini($mircdir\lotto.ini, lotto, chan)
  msg %chan Your lucky numbers are:4 %num1 %num2 %num3 %num4 %num5 %num6 ( $+ %num7 $+ )
}

on 1:TEXT:*:#: {
  if $1 == !lottohelp {
    /notice $nick This script will generate seven numbers. Thats six plus the bonus ball. Note: This is
    /notice $nick for the South African Lottery.
    /notice $nick To generate a set of numbers, simply type !lotto.
    /notice $nick If you have a lucky number that you wish to incorporate, simply type !lottolucky <number>
  }
  if $1 == !lotto {
    msg $chan Calculating Lottery Numbers...
    writeini $mircdir\lotto.ini lotto chan $chan
    /timerlotto 1 10 /lottonum
  }
  if $1 == !lottolucky {
    msg $chan Calculating Lottery Numbers...
    writeini $mircdir\lotto.ini lotto lucky $2
    writeini $mircdir\lotto.ini lotto chan $chan
    /timerlotto2 1 10 /lottonum2
  }
}

Comments

Sign in to comment.
frishy   -  Jan 12, 2009

good work :)

but here's a couple of tips:
You don't need all of the /'s
Using local variables wud be better as they are auto unset when not needed (/var rather than /set)

Also if you want you can replace:

  %num1 = $rand(1,49)
  :tryagainA
  %num2 = $rand(1,49)
  if %num2 = %num1 { /goto tryagainA }
  :tryagainB
  %num3 = $rand(1,49)
  if %num3 = %num2 || %num3 = %num1 { /goto tryagainB }
  :tryagainC
  %num4 = $rand(1,49)
  if %num4 = %num3 || %num4 = %num2 || %num4 = %num1 { /goto tryagainC }
  :tryagainD
  %num5 = $rand(1,49)
  if %num5 = %num4 || %num5 = %num3 || %num5 = %num2 || %num5 = %num1 { /goto tryagainD }
  :tryagainE
  %num6 = $rand(1,49)
  if %num6 = %num5 || %num6 = %num4 || %num6 = %num3 || %num6 = %num2 || %num6 = %num1 { /goto tryagainE }
  :tryagainF
  %num7 = $rand(1,49)
  if %num7 = %num6 || %num7 = %num5 || %num7 = %num4 || %num7 = %num3 || %num7 = %num2 || %num7 = %num1 { /goto tryagainF }
  %chan = $readini($mircdir\lotto.ini, lotto, chan)
  msg %chan Your lucky numbers are:4 %num1 %num2 %num3 %num4 %num5 %num6 ( $+ %num7 $+ )

with

  var %i = 2, %num1 = $r(1,49), %lnumbers = %num1
  while (%i <= 7) {
    var %num [ $+ [ %i ] ] $r(1,49)
    while ($istok(%lnumbers,%num [ $+ [ %i ] ],44)) {
      %num [ $+ [ %i ] ] = $r(1,49)
    }
    %lnumbers = $addtok(%lnumbers,%num [ $+ [ %i ] ],32)
    inc %i
  }
  %chan = $readini($mircdir\lotto.ini, lotto, chan)
  msg $chan Your lucky numbers are:4 %num1 %num2 %num3 %num4 %num5 %num6 $+($chr(40),%num7,$chr(41))

msg $chan $sorttok($deltok(%lnumbers,7,32),32,n) $+($chr(40),%num7,$chr(41))
^ this says the first 6 numbers in order of my code and then the 7th number

and you can replace

  %num1 = $readini($mircdir\lotto.ini, lotto, lucky)
  :tryagainA
  %num2 = $rand(1,49)
  if %num2 = %num1 { /goto tryagainA }
  :tryagainB
  %num3 = $rand(1,49)
  if %num3 = %num2 || %num3 = %num1 { /goto tryagainB }
  :tryagainC
  %num4 = $rand(1,49)
  if %num4 = %num3 || %num4 = %num2 || %num4 = %num1 { /goto tryagainC }
  :tryagainD
  %num5 = $rand(1,49)
  if %num5 = %num4 || %num5 = %num3 || %num5 = %num2 || %num5 = %num1 { /goto tryagainD }
  :tryagainE
  %num6 = $rand(1,49)
  if %num6 = %num5 || %num6 = %num4 || %num6 = %num3 || %num6 = %num2 || %num6 = %num1 { /goto tryagainE }
  :tryagainF
  %num7 = $rand(1,49)
  if %num7 = %num6 || %num7 = %num5 || %num7 = %num4 || %num7 = %num3 || %num7 = %num2 || %num7 = %num1 { /goto tryagainF }
  %chan = $readini($mircdir\lotto.ini, lotto, chan)
  msg %chan Your lucky numbers are:4 %num1 %num2 %num3 %num4 %num5 %num6 ( $+ %num7 $+ )

with

  var %i = 2, %num1 = $readini($mircdir\lotto.ini, lotto, lucky), %lnumbers = %num1
  while (%i <= 7) {
    var %num [ $+ [ %i ] ] $r(1,49)
    while ($istok(%lnumbers,%num [ $+ [ %i ] ],44)) {
      %num [ $+ [ %i ] ] = $r(1,49)
    }
    %lnumbers = $addtok(%lnumbers,%num [ $+ [ %i ] ],32)
    inc %i
  }
  msg $chan Your lucky numbers are:4 %num1 %num2 %num3 %num4 %num5 %num6 $+($chr(40),%num7,$chr(41))
$sorttok($deltok(%lnumbers,7,32),32,n) $+($chr(40),%num7,$chr(41))

They are shorter, it also uses local variables instead of global, although i think its about the same efficiency.

anyway another note is u dont need to write %chan to an ini file you can just set it

  writeini $mircdir\lotto.ini lotto chan $chan 

can be:

  set %chan $chan 

and hen you can remove any of these since its already set:

  %chan = $readini($mircdir\lotto.ini, lotto, chan) 
 Respond  
Red-Dwarf   -  Jan 12, 2009

Thanks for the comment. The script should be 100% now.

 Respond  
undertaker28   -  Jan 11, 2009

i get the msg generating numbers yet it dont produce any

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.