First, the practice of random numbers
1. Randomly generate an integer between the maximum and the minimum value
proc Random {min max} { return [expr round (($max-$min) *rand () +$min)] }
2. Generate a random integer that is not duplicated between Num min to max
Proc randomunique {min Max num} {
Array set arr {}
#如果要求生成的数量超过max和min相减的个数 +1
If {$num >[expr $max-$min +1]} {
Return ""
}
#当生成的随机数量没有达到要求的数量, call a function that generates a random integer
While {[Array size arr]< $num} {
Set x [Random $min $max]
Set arr ($x) ""
}
return [array names arr]
}
3. Random lowercase letters
proc Randlow {} { return122]}
4. Random Uppercase letters
proc Randhigh {} { return)]}
5. Randomly generate a list of content
proc Randlist {lst} { set0 [expr [llength $lst]-1] ]return [lindex $lst $id]}
6. Generate a random lowercase or uppercase letter
proc RANDLH {} { return [rand[randlist {low-high}]}
7. Generate a random uppercase, lowercase letter, or number
proc Randlhn {} { return [rand[randlist {Low High Num}]}
8. Generate a lowercase, uppercase, numeric string with a length of random value between Minlen and MaxLen
proc Randstrlhn {Minlen maxlen} { set len [random $minLen $maxLen] Set ""for {set0} {$i <$len} {incr i} { append str [ RANDLHN] } return $str}
Tcl language Note: Tcl practice