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.

random letter [solved]

Help for those learning Tcl or writing their own scripts.
Post Reply
t
tueb
Halfop
Posts: 76
Joined: Thu Oct 04, 2007 6:09 am
Location: #quiz.de @ irc.gamesurge.net
Contact:

random letter [solved]

Post by tueb »

Hi,

I'm looking for a way to "regsub" a random letter with another random letter. is there an easy way to do that?

thx,

t.
Last edited by tueb on Sun Jan 06, 2008 5:54 am, edited 1 time in total.
#Quiz.de @ irc.GameSurge.net
JavaChat
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Use something like this to generate the random letters:

Code: Select all

#Generating uppercase character
format "%c" [expr 65 + [rand 26]]

Code: Select all

#Generating lowercase character
format "%c" [expr 97 + [rand 26]]
Then simply use one of the digits as your regular expression, and the other as the character to replace with. Use the -nocase option if you'd like the matching to be case-insensitive (will not alter the replacing character however).
NML_375
t
tueb
Halfop
Posts: 76
Joined: Thu Oct 04, 2007 6:09 am
Location: #quiz.de @ irc.gamesurge.net
Contact:

Post by tueb »

works fine, thx =D
#Quiz.de @ irc.GameSurge.net
JavaChat
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

To have alphanumerics you could do a rand() * 60 and check if the result is <= 10 and add 48, or is <= 36 to add 55 and else add 61. (I didn't test the exact result, the adds are +/-1 therefore ^-^)
Just as a remark for the future.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
t
tueb
Halfop
Posts: 76
Joined: Thu Oct 04, 2007 6:09 am
Location: #quiz.de @ irc.gamesurge.net
Contact:

Post by tueb »

thx for that as well^^
#Quiz.de @ irc.GameSurge.net
JavaChat
Post Reply