$randtok

By Cherish on Jan 08, 2007

$randtok - it's returning a random sequence of tokens.

Syntax: $randtok(A,B,C)
A - amount of signs
B - 1 (big letters), 2 (small letters)
C - the ascii value of the character separating the tokens. If not given, signs are by themselves.

Example:
//echo -a $randtok(5,1,32)

//echo -a $randtok(4,2)

alias randtok {
  unset %randtok
  var %a = 1, %b = $1
  while (%a <= %b) {
    var %c $rand(1,2)
    if (%c == 1) var %randtok. [ $+ [ %a ] ] $rand(0,9)
    else var %randtok. [ $+ [ %a ] ] $iif($2 == 1,$rand(A,Z),$rand(a,z))
    inc %a
  }
  var %c = 1, %d = $var(%randtok.*,0)
  while (%c <= %d) {
    set %randtok $+(%randtok,$chr($3),$var(%randtok.*,%c).value)
    inc %c
  }
  return $iif($chr($3) == $left(%randtok,1),$right(%randtok,$calc($len(%randtok) - 1)),%randtok)
}

Comments

Sign in to comment.
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.