A user sent me some code he was having trouble with, and in the code I saw a rather verbose and complex block of CFML being used to generate random strings for use with CAPTCHA verifications. So, while replying to his e-mail, I also sent him the RandString() function I use myself. And, as it may be of use others, here it is:
<!--- Generate random strings of specified length --->
<cffunction name="RandString" output="no" returntype="string">
<cfargument name="length" type="numeric" required="yes">
<!--- Local vars --->
<cfset var result="">
<cfset var i=0>
<!--- Create string --->
<cfloop index="i" from="1" to="#ARGUMENTS.length#">
<!--- Random character in range A-Z --->
<cfset result=result&Chr(RandRange(65, 90))>
</cfloop>
<!--- Return it --->
<cfreturn result>
</cffunction>
There are no comments for this entry.
[Add Comment]