问题
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 ?
回答1:
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
}
回答2:
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
回答3:
Smart sentence, word, nick builder command:
/regdom
//echo $regword(3,10).text-30
Example:
gezodifix sebiy podagafiw curetumubih gidaharik tibovifec lacuxujor tumihugob yiwosinok nifabatuv boyeces cadamujez wuz nowafeh webenevip wekegibis herumeyab wefehadal jocavor kasitijor wizepijab givepulec pafucuk cebohes yirujisap xer nucupiyas lugob dogev moy
have fun
alias regword { noop $regex($prop,/(\d+$)) | var %i-l $regml(1) | while %i-l { var %imp $addtok(%imp,$regdom($1,$2).w,32) | dec %i-l } | return %imp }
alias regdom {
if !$isid {
var %e- echo 5
%e- *** Commands:
%e- *** $!regdom(N,N).w N<N 1-10 From 1 to 10 character random words
%e- : $!regdom(3,10).w $!regdom(3,10)
%e- :*** Command KEY & Result:
%e- : W DUKEPOGEH
%e- : w dukepogeh
%e- : WR Mix
%e- : NR WILIXENIKIZUPOG_74
%e- : nr zeritacen^49
%e- : Mix mixing special characters H^a]y|u^M]A-g´
%e- : *** BONUS
%e- : ipsum regular word $!regword(3,10).text-10
%e- : Letters of words in the range of 3 to 10. 10 words creates Sentence
}
if $isid {
if $1 < $2 && $2 > 40 { echo 4 *** The maximum length value should be 1<40 | return }
if $1 < $2 && $2 <= 40 {
var %l' $r($1,$2),%s' a e i o u ,%a' b c d f g h j k l m n p r s t v x w y z . | :r
var %k' $addtok(%k',$gettok(%a',$r(1,$numtok(%a',32)),32),32)
if $len(%k') < %l' goto r
if $len(%k') >= %l' {
var %s- _.-.|.\.[.].^.´
var %r1 $regsubex($regsubex(%k',/(\W)/ig,$gettok(%s',$r(1,$numtok(%s',32)),32)),/([a-f]|[c-g]|[h-z])/g,$iif($r(0,20) > 15,$upper(\t),\t))
var %r2 $+($gettok(%s-,$r(1,$gettok(%s-,0,46)),46),$r(18,85))
var %r3 $regsubex($regsubex(%k',/(\W)/ig,$gettok(%s',$r(1,$numtok(%s',32)),32)),/([a-f]|[c-g]|[h-z])/g,$iif($r(1,100) > 10, $&
$+($iif($r(0,20) > 15,$upper(\t),\t),$gettok(%s-,$r(1,$gettok(%s-,0,46)),46)),$iif($r(0,20) > 15,$upper(\t),\t)))
if $prop === NR return $+($upper(%r1),%r2)
if $prop === nr return $+($lower(%r1),%r2)
if $prop === W return $upper(%r1)
if $prop === w return $lower(%r1)
if $prop === mix return %r3
if $prop === WR || !$prop { return $iif($r(1,10) > 5,%r1,$+(%r1,%r2)) }
else echo 5 *** incorrect key | return
} }
else echo 5 ***Incorrect or missing parameters..
} }
来源:https://stackoverflow.com/questions/33861748/script-to-generate-random-string-not-working