0

I'm trying to generate random string with white spaces but it is not working :

/rs {
  %i=1
  %r=$rand(1,50)
  %s=$rand(a,z)
  while(%i <= %r) {
    %i=%i+1
    %s=%s $+ $rand(a,z)
    if(1 == rand(1,4) %s=%s $+ $chr(32)
  }
  echo %s
}

Returns :

WHILE(%I Unknown command

Any ideas ?

Wicelo
  • 2,358
  • 2
  • 28
  • 44

2 Answers2

2

You had some issues, those are just few of them.

  • Spaces: mSL statements are sensebile when it concerns to spaces, those you should put spaces between the while (expression), if (expression) and even %i = 1 and %r = $rand(1,50) etc'

  • Parenthesis: You probably have forgotten the little parenthesis at the space generator condition. Should be if (1 == rand(1,4)) %s=%s $+ $chr(32)

  • $ sign: You also forgotten to put this sign before this identifier rand(1,4) should be $rand(1,4)

Fixed Snippet:

rs {
  %i = 1
  %r = $rand(1,50)
  %s = $rand(a,z)
  while (%i <= %r) {
    %i = %i + 1
    %s = %s $+ $rand(a,z)
    if (1 == $rand(1,4)) %s = %s $chr(32)

  }
  echo -ag %s
}

I took the liberty of designing the code a bit different, now you can use it as $identifier instead of an alias, which will give you further flexibility and usability.

Usages:

  • echo -ag $rs (default will be 50 characters long)
  • echo -ag $rs(20) (random string with length of 20 charcathers)
  • set %myName $rs(15) (will save the output random string into a constant variable)

Snippet:

rs {
  if (!$1) {
    tokenize 32 50
  }

  var %randString
  var %randStringLength = $rand(1, $1)
  var %i = 1
  while (%i <= %randStringLength) {
    %randString = %randString $+ $rand(a, z)
    if ($rand(1, 4) == 1) {
      %randString = %randString $chr(32)
    }
    inc %i
  }
  return %randString
}
Orel Eraki
  • 11,940
  • 3
  • 28
  • 36
0

This goes to the ALIAS tab. Use /SET to affect variables in mIRC. Also, put spaces before and after your parenthesis. You also forgot a $ before rand in the IF. I also had to remove $+ in the $chr(32) affectation, otherwise it doesn't work. That's mIRC scripting for you. :)

/rs {
  /set %i 1
  /unset %s
  /set %r $rand(1,50)
  while ( %i <= %r ) {
    /set %i %i + 1
    /set %s %s $+ $rand(a,z)
    if ( 1 == $rand(1,4) ) /set %s %s $chr(32)
  }
  echo %s
}

A few results this gives me :

oe ucrifaktgl qkr fn ydjujclgmc dob hlx rtgnqenhdy f
x gtnr ly qx j
stvusfvfrn y
z sj g aign zx royjbvkcu a t x b
m d
nttyckhwfaufoqjordfecn ib k xsl
adupbnnwoxt q
rzvlytv
pd
o ycj eq
Guillaume F.
  • 5,905
  • 2
  • 31
  • 59