This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.
For more information, see this announcement post . Click the X in the top right-corner of this box to dismiss this message.
Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
simo
Revered One
Posts: 1082 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Sun Jun 14, 2020 8:11 am
Code: Select all
proc randomRangeString {length {chars "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"}} {
set range [expr {[string length $chars]-1}]
set txt ""
for {set i 0} {$i < $length} {incr i} {
set pos [expr {int(rand()*$range)}]
append txt [string range $chars $pos $pos]
}
return $txt
}
when using this random string proc is there a way to output 3 different results in this because atm it seems to produce 3 same outputs:
set newPassX [randomRangeString 8]
:$::network-$newPassX.$newPassX.$newPassX.IP
simo
Revered One
Posts: 1082 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Sun Jun 14, 2020 3:05 pm
basically was wondering if this proc could be changed to output 4 different strings of 8
like this:
$::network.randomstingof8.randomstingof8.randomstingof8.IP
CrazyCat
Revered One
Posts: 1244 Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:
Post
by CrazyCat » Sun Jun 14, 2020 6:46 pm
Add an argument to the proc:
Code: Select all
# usage : randomString <length> <iterations>
proc randomString { length iter } {
set chars "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
set range [string length $chars]
set rlist {}
for {set j 0 } {$j < $iter} {incr j} {
set txt ""
for {set i 0} {$i < $length} {incr i} {
set pos [expr {int(rand()*$range)}]
append txt [string index $chars $pos]
}
lappend rlist $txt
}
return $rlist
}
simo
Revered One
Posts: 1082 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Mon Jun 15, 2020 8:56 am
excellent tnx CrazyCat that works exactly as intented
CrazyCat
Revered One
Posts: 1244 Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:
Post
by CrazyCat » Mon Jun 15, 2020 9:53 am
Just a short modification:
Code: Select all
proc randomString { {length 8} {iter 1} } {
This will allow to:
- simply call randomString => will return 1 random string of 8 chars
- call randomString X (X is integer)=> will return 1 random string of X chars
- call randomString X Y (X and Y are integer)=> will return Y random strings of X chars
simo
Revered One
Posts: 1082 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Mon Jun 15, 2020 10:25 am
oh thats even better tnx CrazyCat