|
monk
|
monk
|
if i have %var var1 var2 var3 var4
is there i way i can make random mixing these var1 var2 var3 var4?
|
|
|
|
clutz1572
|
clutz1572
|
if i understand your request correctly perhaps you could try somthing like this:
%var = $rand(%v1,%v4)
that would randomize the result..
|
|
|
|
monk
|
monk
|
i want to mix them up like this:
%var var2 var3 var4 var1 %var var1 var4 var3 var2
and so on....
|
|
|
|
DaveC
|
DaveC
|
alias mixup {
tokenize 32 $$1-
var %return
while ($0) {
var %return = $instok(%return,$1,$rand(1,$calc($numtok(%return,32) + 1)),32)
tokenize 32 $2-
}
return %return
}
usage. var %var = $mixup(%var)
|
|
|
|
Joined: Feb 2004
Posts: 2,013
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,013 |
Usage: $rtok(string,N,C) Examples: //echo -a $rtok(a.b.c,1-,46) //echo -a $rtok(this is a test,2,32) alias rtok {
if $1 == $null || $remove($2,-) !isnum || $3 !isnum 1-255 { return }
var %a = 1, %b = $2, %c = $3, %d
tokenize $3 $1
while $($ $+ %a,2) != $null {
%d = $instok(%d,$v1,$r(1,%a),%c)
inc %a
}
return $gettok(%d,%b,%c)
}
|
|
|
|
DaveC
|
DaveC
|
very nice!
I couldnt work out why the second example kept coming back with one word, then it dawned on me 2 stood for token 2 DOH! not 2 tokens, wheres the panadole!
|
|
|
|
Joined: Feb 2004
Posts: 2,013
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,013 |
Hehe, it is indeed a bit strange I suppose that the range works like the other *tok identifiers. Like $rtok(a b c,2,32) is going to return the second random token, but the second is actually irrelevant. It means any random token if you look at it. Therefore it might be best to make the N equal to number of tokens you want returned with: 0 = all tokens N = N tokens Usage: $rwords(string,N,C) Examples: $rwords(a b c d,0,32) returns all space delimited tokens randomized fex "b d a c" $rwords(1.2.3.4.5.6,3,46) returns 3 dot delimited random numbers fex "4.1.6" alias rwords {
if $1 == $null || $2 !isnum 0- || $3 !isnum 1-255 { return }
var %a = $1, %b = $numtok(%a,$3), %c = $iif(!$2 || $2 > %b,%b,$2), %d, %e
while %c {
%d = $r(1,%b)
%e = $instok(%e,$gettok(%a,%d,$3),1,$3)
%a = $deltok(%a,%d,$3)
dec %b | dec %c
}
return %e
}
|
|
|
|
DaveC
|
DaveC
|
Thats what initially though me I new they were random so didnt connect grabbing any particular tokens as being important.
Yeah i like this one even better now tho
oh err $rwords(a b c d,0,32) returned me "d b c a" & $rwords(1.2.3.4.5.6,3,46) returned me "3.1.5" something must be broken!
(lol no no just joking im not that doped up today!)
|
|
|
|
Joined: Feb 2004
Posts: 2,013
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,013 |
lol
(I could have optimized that $iif to $iif(%b - $2 > 0,$2,%b), but it's too late to edit now, teehee)
|
|
|
|
monk
|
monk
|
You guys are genius lol thank you
|
|
|
|
|