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.

generate random alphabetical chars between 5 and 10

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

generate random alphabetical chars between 5 and 10

Post by simo »

hey there gents,

i was wondering what would be the proper way to generate random a-zA-z
chars between 5 and 10

like

HgfdH
Qaygfff
Xwqyttoooo

and so on
User avatar
CrazyCat
Revered One
Posts: 1236
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

You mean an adaptation of the script requested @ http://forum.egghelp.org/viewtopic.php?p=108557 ?

Code: Select all

# usage : randString <min> <max>
proc randString { {min 1} {max 8} } {
	set chars "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
	set size [expr {int(rand()*($max-$min+1)+$min)}]
	set range [string length $chars]
	set txt ""
	for {set i 0} {$i < $size} {incr i} {
		set pos [expr {int(rand()*$range)}]
		append txt [string index $chars $pos]
	}
	return $txt
}
If min is not defined, it's between 1 and 8 chars.
If min is defined, between <min> and 8 chars long (min must be lower than 8, I didn't check the values)
If min and max are defined, it's between <min> and <max> chars long (idem)
s
simo
Revered One
Posts: 1078
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

Oh i totally forgot about that post thanx crazycat
Post Reply