frishy commented on a Page, Lotto Generator  -  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  
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.