Here's the function I use:
<cffunction name="generateShortCode" access="public" output="false"
returntype="string">
<!--- Create a 6 digit, base 32 code that will be used to identify
this particular user--->
<cfscript>
var numberToUse = RandRange(1,1000000000,"SHA1PRNG");
var shortcode = FormatBaseN(numberToUse,32);
</cfscript>
<cfscript>
while(Len(shortcode) LT 6){
shortcode = '0'&shortcode;
}
</cfscript>
<cfreturn shortcode />
</cffunction>
Obviously that generates a 6 character string, not a 4 character
string, but change the 6 to a 4 and Bob's your Uncle.
Judah
On Wed, Feb 10, 2010 at 10:50 AM, Les Irvin <[email protected]> wrote:
>
> How would I come up with a 4-character random string consisting of any
> letter or number?
> 1k3d, e4rf, 69e4, dfje, 3967, etc...
>
> Thanks in advance for your help,
> Les
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know
on the House of Fusion mailing lists
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:330557
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4