$randtok

By Arigateaux on Feb 27, 2014

This works just like $shufftok(), except it adds a third element to it by request from Vegito on LucidChat.

;// $randtok(text, N, C)
;//                                     This essentially works just like $sufftok()
;// $randtok(this is a test, 4, 32)     ->  a is this test
;//
;//                                     This works by randomizing the tokens and then just grabbing extra
;//                                     tokens from the original to satiate the requirement.
;// $randtok(this is a test, 10, 32)    -> a this a test test is this test a is
alias randtok {
  if ($2 !isnum) return
  var %a = $1
  var %b = $2
  var %c = $iif($3 != 32, $3, 32)
  tokenize %c %a
  var %i = $iif($2 < $0, $2, $0)
  while (%b) {
    if (%i < 1) {
      %t = $instok(%t, [ $ $+ [ $r(1, $0) ] ], %r, %c)
      dec %b
      continue
    }
    var %r = $r(1, %i)
    var %t = $instok(%t, $gettok(%a, %r, %c), %i, %c)
    %a = $deltok(%a, %r, %c)
    dec %i
    dec %b
  }
  return %t
}

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.