CFLib.org – Common Function Library Project

getRandString(stringLenth)

Last updated February 3, 2004

author

Kenneth Rainey

Version: 1 | Requires: CF5 | Library: StrLib

Description:
getRandString is an easy-to-use random string generator. Pass it a integer, and it returns a random alphanumeric string of the specified length.

Return Values:
Returns a string.

Example:

<cfoutput>#getRandString(15)#</cfoutput>

Parameters:

Name Description Required
stringLenth Length of random string to generate. Yes

Full UDF Source:

/**
 * Returns a random alphanumeric string of a user-specified length.
 * 
 * @param stringLenth 	 Length of random string to generate. (Required)
 * @return Returns a string. 
 * @author Kenneth Rainey (kip.rainey@incapital.com) 
 * @version 1, February 3, 2004 
 */
function getRandString(stringLength) {
	var tempAlphaList = "a|b|c|d|e|g|h|i|k|L|m|n|o|p|q|r|s|t|u|v|w|x|y|z";
	var tempNumList = "1|2|3|4|5|6|7|8|9|0";
	var tempCompositeList = tempAlphaList&"|"&tempNumList;
	var tempCharsInList = listLen(tempCompositeList,"|");
	var tempCounter = 1;
	var tempWorkingString = "";
	
	//loop from 1 to stringLength to generate string
	while (tempCounter LTE stringLength) {
		tempWorkingString = tempWorkingString&listGetAt(tempCompositeList,randRange(1,tempCharsInList),"|");
		tempCounter = tempCounter + 1;
	}
	
	return tempWorkingString;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson