CFLib.org – Common Function Library Project

RandomizeString(theString, theLength)

Last updated May 9, 2009
Download UDF

author

Stephen Withington Stephen Withington

Version: 0 | Requires: ColdFusion 5 | Library: StrLib

 
Rated 4 time(s). Average Rating: 4.8

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>

Search CFLib.org


Latest Additions

Alan McCollough Alan McCollough added
forceBoolean
5 day(s) ago

Shawn Porter Shawn Porter added
DeMoronize
8 day(s) ago

Chris Carey Chris Carey added
readPropertiesFi...
8 day(s) ago

Randy Johnson Randy Johnson added
lastDayofWeek
11 day(s) ago

Top Rated

Barney Boisvert indentXml
Rated 5.0, 4 time(s)

James Sleeman                                     QuickSort
Rated 5.0, 3 time(s)

Nathan Dintenfass                                 queryColumnsToSt...
Rated 5.0, 3 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 3 time(s)

Created by Raymond Camden / Design by Justin Johnson