### CRand.tcl 2.0.0 x9A3HLgz #REQUIREMENTS # PBinScr.tcl fMrtKqyq #LICENSE # Copyright © 2013 Alberto Dietze "DoctorD90" # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # Full GPLv3 Text: http://www.gnu.org/licenses/gpl.txt #PATERNITY #Coder: DoctorD90 #Network: irc.OnlineGamesNet.net #Chan: #eHito #Mail: DoctorD90@EggTcl.tk #PURPOSE #Create Random codes of fixed length. #USAGE #set var [crand CodeLength ?CharsTyp? ?CaseSens?] #-CodeLength: # How many chars must be the code. #-CharsTyp (Default 0 # 0 Numbers # 1 Letters # 2 Alfa Numeric #-CaseSens (Default 0) # 0 Capital Letter # 1 Low Letter # 2 Random ### DON'T EDIT ANYTHING BELOW ### proc crand {len {typ {0}} {case {0}}} { if {![string is integer -strict $len]} { return "[list -1 "\002$len\002 Must Be A Number"]" } if {![string is integer -strict $typ]} { return "[list -1 "\002$typ\002 Must Be A Number"]" } if {![string is integer -strict $case]} { return "[list -1 "\002$case\002 Must Be A nNmber"]" } set a 0 set b 35 if {$typ} { set a 10 } if {!$typ} { set b 9 } set i 0 set code "" set gap [expr {$b - $a + 1}] while {$i != $len} { set c [expr {int(rand() * $gap) + $a}] switch -regexp -- $c { ^10$ { set c "A" } ^11$ { set c "B" } ^12$ { set c "C" } ^13$ { set c "D" } ^14$ { set c "E" } ^15$ { set c "F" } ^16$ { set c "G" } ^17$ { set c "H" } ^18$ { set c "I" } ^19$ { set c "J" } ^20$ { set c "K" } ^21$ { set c "L" } ^22$ { set c "M" } ^23$ { set c "N" } ^24$ { set c "O" } ^25$ { set c "P" } ^26$ { set c "Q" } ^27$ { set c "R" } ^28$ { set c "S" } ^29$ { set c "T" } ^30$ { set c "U" } ^31$ { set c "V" } ^32$ { set c "W" } ^33$ { set c "X" } ^34$ { set c "Y" } ^35$ { set c "Z" } } if {$type != "0"} { if {$case || [rand 2]} { set c [string tolower $c] } } append code $c incr i } return $code } ### putlog "CRand.tcl LOADED"