Shuffle algorithm
Posted by Sigh
Monday, August 30, 2004
Description: Return randomized numbers or tokens


;; Shuffle alias by Sigh
;; Usage: $shuffle(N,C)
;; Shuffle algorithm used to generate N amount of numbers delimited by character with ascii number C
;; For example: $shuffle(10,44) can equal 1,5,4,7,3,6,10,8,9,2
;; Users with mIRC versions less than 6.16 must replace $v1 with $ifmatch in the following code

alias shuffle {
  var %m
  while ($numtok(%m,$2) < $1) %m = $instok(%m,$calc(1+$v1),$r(0,$v1),$2)
  return %m
}

;; An adaption of the above alias, used to randomize a list of tokens
;; Usage: $shuffle2(string,C)
;; For example $shuffle2(my!list!of!tokens,33) can equal of!tokens!my!list

alias shuffle2 {
  var %m
  while ($numtok(%m,$2) < $numtok($1,$2)) %m = $instok(%m,$gettok($1,$calc(1+$v1),$2),$r(0,$v1),$2)
  return %m
}
neat
Posted by KilledInAction
Thursday, September 02, 2004 09:09pm PDT
i haven't looked too much into it, but this looks like a neat little snippet to keep around.
Submit a comment
Oops! You need to login or register before you can post a comment!

ebaum's world