View difference between Paste ID: x9A3HLgz and RQcUch3q
SHOW: | | - or go back to the newest paste.
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
#Mail: [email protected]
29
30
#PURPOSE
31
#Create Random codes of fixed length.
32
33
#USAGE
34
#set var [crand CodeLength ?CharsTyp? ?CaseSens?]
35
#-CodeLength:
36
#  How many chars must be the code.
37-
#-CharsTyp (Default 0
37+
#-CharsTyp: (Default 0)
38
#  0  Numbers
39
#  1  Letters
40
#  2  Alfa Numeric
41-
#-CaseSens (Default 0)
41+
#-CaseSens: (Default 0)
42
#  0  Capital Letter
43
#  1  Low Letter
44
#  2  Random
45
46
47
### DON'T EDIT ANYTHING BELOW ###
48
49
proc crand {len {typ {0}} {case {0}}} {
50
  if {![string is integer -strict $len]} {
51
    return "[list -1 "\002$len\002 Must Be A Number"]"
52
  }
53
  if {![string is integer -strict $typ]} {
54
    return "[list -1 "\002$typ\002 Must Be A Number"]"
55
  }
56
  if {![string is integer -strict $case]} {
57
    return "[list -1 "\002$case\002 Must Be A nNmber"]"
58
  }
59
  set a 0
60
  set b 35
61
  if {$typ} {
62
    set a 10
63
  }
64
  if {!$typ} {
65
    set b 9
66
  }
67
  set i 0
68
  set code ""
69
  set gap [expr {$b - $a + 1}]
70
  while {$i != $len} {
71
    set c [expr {int(rand() * $gap) + $a}]
72
    switch -regexp -- $c {
73
      ^10$ { set c "A" }
74
      ^11$ { set c "B" }
75
      ^12$ { set c "C" }
76
      ^13$ { set c "D" }
77
      ^14$ { set c "E" }
78
      ^15$ { set c "F" }
79
      ^16$ { set c "G" }
80
      ^17$ { set c "H" }
81
      ^18$ { set c "I" }
82
      ^19$ { set c "J" }
83
      ^20$ { set c "K" }
84
      ^21$ { set c "L" }
85
      ^22$ { set c "M" }
86
      ^23$ { set c "N" }
87
      ^24$ { set c "O" }
88
      ^25$ { set c "P" }
89
      ^26$ { set c "Q" }
90
      ^27$ { set c "R" }
91
      ^28$ { set c "S" }
92
      ^29$ { set c "T" }
93
      ^30$ { set c "U" }
94
      ^31$ { set c "V" }
95
      ^32$ { set c "W" }
96
      ^33$ { set c "X" }
97
      ^34$ { set c "Y" }
98
      ^35$ { set c "Z" }
99
    }
100
    if {$type != "0"} {
101
      if {$case || [rand 2]} {
102
        set c [string tolower $c]
103
      }
104
    }
105
    append code $c
106
    incr i
107
  }
108
  return $code
109
}
110
111
###
112
putlog "CRand.tcl LOADED"