DoctorD90

CRand.tcl

Apr 19th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### CRand.tcl 2.0.0 x9A3HLgz
  2.  
  3. #REQUIREMENTS
  4. # PBinScr.tcl fMrtKqyq
  5.  
  6. #LICENSE
  7. # Copyright © 2013 Alberto Dietze "DoctorD90"
  8. #
  9. #    This program is free software: you can redistribute it and/or modify
  10. #    it under the terms of the GNU General Public License as published by
  11. #    the Free Software Foundation, either version 3 of the License, or
  12. #    (at your option) any later version.
  13. #
  14. #    This program is distributed in the hope that it will be useful,
  15. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. #    GNU General Public License for more details.
  18. #
  19. #    You should have received a copy of the GNU General Public License
  20. #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. # Full GPLv3 Text: http://www.gnu.org/licenses/gpl.txt
  23.  
  24. #PATERNITY
  25. #Coder: DoctorD90
  26. #Network: irc.OnlineGamesNet.net
  27. #Chan: #eHito
  28.  
  29. #PURPOSE
  30. #Create Random codes of fixed length.
  31.  
  32. #USAGE
  33. #set var [crand CodeLength ?CharsTyp? ?CaseSens?]
  34. #-CodeLength:
  35. #  How many chars must be the code.
  36. #-CharsTyp: (Default 0)
  37. #  0  Numbers
  38. #  1  Letters
  39. #  2  Alfa Numeric
  40. #-CaseSens: (Default 0)
  41. #  0  Capital Letter
  42. #  1  Low Letter
  43. #  2  Random
  44.  
  45.  
  46. ### DON'T EDIT ANYTHING BELOW ###
  47.  
  48. proc crand {len {typ {0}} {case {0}}} {
  49.   if {![string is integer -strict $len]} {
  50.     return "[list -1 "\002$len\002 Must Be A Number"]"
  51.   }
  52.   if {![string is integer -strict $typ]} {
  53.     return "[list -1 "\002$typ\002 Must Be A Number"]"
  54.   }
  55.   if {![string is integer -strict $case]} {
  56.     return "[list -1 "\002$case\002 Must Be A nNmber"]"
  57.   }
  58.   set a 0
  59.   set b 35
  60.   if {$typ} {
  61.     set a 10
  62.   }
  63.   if {!$typ} {
  64.     set b 9
  65.   }
  66.   set i 0
  67.   set code ""
  68.   set gap [expr {$b - $a + 1}]
  69.   while {$i != $len} {
  70.     set c [expr {int(rand() * $gap) + $a}]
  71.     switch -regexp -- $c {
  72.       ^10$ { set c "A" }
  73.       ^11$ { set c "B" }
  74.       ^12$ { set c "C" }
  75.       ^13$ { set c "D" }
  76.       ^14$ { set c "E" }
  77.       ^15$ { set c "F" }
  78.       ^16$ { set c "G" }
  79.       ^17$ { set c "H" }
  80.       ^18$ { set c "I" }
  81.       ^19$ { set c "J" }
  82.       ^20$ { set c "K" }
  83.       ^21$ { set c "L" }
  84.       ^22$ { set c "M" }
  85.       ^23$ { set c "N" }
  86.       ^24$ { set c "O" }
  87.       ^25$ { set c "P" }
  88.       ^26$ { set c "Q" }
  89.       ^27$ { set c "R" }
  90.       ^28$ { set c "S" }
  91.       ^29$ { set c "T" }
  92.       ^30$ { set c "U" }
  93.       ^31$ { set c "V" }
  94.       ^32$ { set c "W" }
  95.       ^33$ { set c "X" }
  96.       ^34$ { set c "Y" }
  97.       ^35$ { set c "Z" }
  98.     }
  99.     if {$type != "0"} {
  100.       if {$case || [rand 2]} {
  101.         set c [string tolower $c]
  102.       }
  103.     }
  104.     append code $c
  105.     incr i
  106.   }
  107.   return $code
  108. }
  109.  
  110. ###
  111. putlog "CRand.tcl LOADED"
Advertisement