CFLib.org – Common Function Library Project

RandomizeString(theString, theLength)

Last updated May 9, 2009

author

Stephen Withington

Version: 0 | Requires: CF5 | Library: StrLib

Description:
Pass in a string and I'll return a randomized string value at the length you desire.

Return Values:
returns a string

Example:

<cfoutput>#RandomizeString("0123456789ABCDEF", 32)#</cfoutput>

Parameters:

Name Description Required
theString string of text to randomize Yes
theLength length of random string to create Yes

Full UDF Source:

<!---
 I generate a randomized string of desired length.
 
 @param theString 	 string of text to randomize (Required)
 @param theLength 	 length of random string to create (Required)
 @return returns a string 
 @author Stephen Withington (steve@stephenwithington.com) 
 @version 0, May 9, 2009 
--->
<cffunction name="RandomizeString" returntype="string" output="false" access="public" 
			hint="pass me a string and desired length and i'll randomize it for you.">
	<cfargument name="theString" type="string" required="true" default="0123456789ABCDEF" />
	<cfargument name="theLength" type="numeric" required="true" default="32" />
	<cfset var randomizedString = "" />
	<cfset var theIndex = "" />

	<cfloop index="theIndex" from="1" to="#val(arguments.theLength)#" step="1">
		<cfset randomizedString = randomizedString & mid(arguments.theString, rand()*len(arguments.theString)+1, 1) />
	</cfloop>
	<cfreturn randomizedString />	
</cffunction>
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