mIRC Home    About    Download    Register    News    Help

Print Thread
#116392 04/04/05 05:28 PM
Joined: Feb 2003
Posts: 12
M
monk Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Feb 2003
Posts: 12
if i have %var var1 var2 var3 var4

is there i way i can make random mixing these var1 var2 var3 var4?

#116393 04/04/05 06:12 PM
Joined: Aug 2004
Posts: 423
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Aug 2004
Posts: 423
if i understand your request correctly perhaps you could try somthing like this:

%var = $rand(%v1,%v4)

that would randomize the result..

#116394 04/04/05 06:23 PM
Joined: Feb 2003
Posts: 12
M
monk Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Feb 2003
Posts: 12
i want to mix them up like this:

%var var2 var3 var4 var1
%var var1 var4 var3 var2

and so on....

#116395 04/04/05 11:37 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Code:
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)

#116396 04/04/05 11:53 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Usage: $rtok(string,N,C)

Examples:

//echo -a $rtok(a.b.c,1-,46)
//echo -a $rtok(this is a test,2,32)

Code:
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)
}


Gone.
#116397 05/04/05 12:14 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
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!

#116398 05/04/05 12:43 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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"

Code:
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
}


Gone.
#116399 05/04/05 08:24 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
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!)

#116400 05/04/05 09:06 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
lol


(I could have optimized that $iif to $iif(%b - $2 > 0,$2,%b), but it's too late to edit now, teehee)


Gone.
#116401 25/04/05 04:42 PM
Joined: Feb 2003
Posts: 12
M
monk Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Feb 2003
Posts: 12
You guys are genius lol thank you


Link Copied to Clipboard