$_randstring

By da^hype on Mar 24, 2005

Returns a random string based on inputted information.

/*
URL  : www.hirc.org / www.mircmalaysia.com
email: da-hype@hirc.org
Thanks to Sigh_ for helping me improve code.

Returns a random string.
Usage: $_randstring(flags,length)
Flags:
n - numbers
l - lowercase
u - uppercase
c - other ascii characters
*/
alias _randstring {
  var %i = 1,%flag = $1,%n = $2,%x,%s
  ;checks for invalid flags
  if (n !isin %flag) && (l !isin %flag) && (u !isin %flag) && (c !isin %flag) _err Unknown flags: %flag
  ;checks for invalid integers
  if (%n !isnum) || (%n < 1) _err Invalid integer: %n
  ;limits max %n to 900
  if (%n > 900) %n = 900
  ;loops threw flags and randomize
  while (%i <= %n) {
    %s = $replacex(%flag,n,$r(1,9),l,$r(a,z),u,$r(A,Z),c,$chr($r(126,255)))
    %x = $+(%x,$mid(%s,$r(1,$len(%s)),1))
    inc %i
  }
  ;returns value
  if (%x) return %x
  else halt
}
alias -l _err {
  var %a = $+(,$color(info text)) $+ ERROR: <command>
  echo -a $replace(%a,<command>,$1-)
}

Comments

Sign in to comment.
LIQUID_NiTrO   -  Mar 26, 2005

Very cool dude. This will be great for generating passwords in times when a user can\'t specify their own.

 Respond  
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.