[color:00007F]qwerty[/color]:
I did know letters are unaffected, though I didn't really remember it until someone mentioned it; however, since I was using the the $asc() value of the letters, I had to take into account the edge number problem, which is why I did it the way I did. As I mentioned to you on EFnet, I did it this way to allow case sensitivity and omit intervening [\]^_` between upper and lower case (ASCII 91-96). $rand will allow $rand(A,Z) or $rand(a,z) but not $rand(A,z).

Raccoon:
It does not support number only because he did not ask for it to do so. That is why I specifically checked !isletter instead of !isalnum. Removing the check simplifies the code and you can specify any kind of range you wish, including not only letters but also punctuation or high ASCII as well. Here are my original results as posted to this forum for reference.

As far as the portion of the code to double (or more) the letters, I left that as an exercise for the poster for specific reasons.
  • There was no intented use specified and I can easily visualize ways this sort of thing can be used maliciously.
  • There would need to be some sort of formatting design decisions made which are not evident in the original post. For example, how will it handle $rand(a,ZZZZZ) or $rand(zzzz,a). Note that both are "backwards" in addition to being of differing lengths. Thus, they are interpretable in multiple ways, none of which were expressed in the original post.
  • No data validation was mentioned, which is why I only included the sole check indicated by that post. As I left it, it is possible to specify a backward range. Since $!rand(15,1) works (even though $!rand(z,a) doesn't) and my method converts to ASCII first, my version can handle backward ranges.
  • On another, more careful, reading of the original post, the first character of the first parameter is the lower bound and the first character of the second parameter is the upper bound for that character position in the result string. This would be simple enough to accomplish in an alias that wraps $randletter(), passing it $mid($1,%i,1) and $mid($2,%i,1) if you assume (or correct for, as below) that $1 and $2 will be of equal length; again, though, you might need data validation for each loop iteration.
    Code:
    
    alias multirand {
      var %result, %1 = $left($1,$len($$2)), %2 = $left($2,$len(%1)), %i = 1, %limit = $calc($len(%1) + 1)
      while %i < %limit { var %result = $+(%result,$randletter($mid(%1,%i,1),$mid(%2,%i,1))), %i = %i + 1 }
      return %result
    }

    //echo -a * $multirand(aa,bz) $multirand(aaa,bft)
    * at bdj
  • Perhaps I erred in allowing upper-case letters to be mixed with lower-case letters and should have just $lower()'d the input, since that is how it was presented in the original suggestion.
These are my reasons for leaving the scripted reply in the state I did. The omissions were intentional.

Personally, if I were the one designing it, I would change the format entirely and use $multirand(<valid characters (ranges allowed)>, [length]) where $mutlirand(0-9A-Za-z,3) might return g3A, and the length parameter is optional, defaulting to 1. This would be even simpler to implement, since you just have two loops, the outer loop builds the string and var %re = /([ $+ $1 $+ ])/), then the inner loop is a simple while $regex($rand(%low,%high), %re) == 0 { continue } and then build %result = $+(%result,$regml(1)). The error checking and determining %low and %high would take longer to write than the actual meat of the code. This method will probably be slower, though, since it calls $regex.

If you've made it this far, kudos and cookies are at the table on the left. I hope I haven't left any questions you had about my code or the reasons behind it unaddressed.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C