
CFML Generating Random String
While working on one of my client’s projects, I’ve encountered the need of generating RANDOM strings. Since, as almost, any other language, Cold Fusion does not have any type of support for this functionality, I had to create a function of my own.
Hope you find it useful.
<cfscript> function RandomString(length, chars="ABCDEFGHIJKLMNOPQRST0123456789-") { var i = 0; var theString = ""; for (i = 0; i < length; i++) { theString &= Mid(chars, RandRange(1, len(chars), "SHA1PRNG"), 1); } return theString; } </cfscript>