Top
CFML Generating Random String – Dragos Cirjan
fade
728
post-template-default,single,single-post,postid-728,single-format-standard,eltd-core-1.1.1,flow child-child-ver-1.0.0,flow-ver-1.3.6,,eltd-smooth-page-transitions,ajax,eltd-blog-installed,page-template-blog-standard,eltd-header-standard,eltd-fixed-on-scroll,eltd-default-mobile-header,eltd-sticky-up-mobile-header,eltd-dropdown-default,wpb-js-composer js-comp-ver-5.0.1,vc_responsive

Warning: A non-numeric value encountered in /usr/src/wordpress/wp-content/themes/flow/framework/modules/title/title-functions.php on line 417

CFML Generating Random String

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>
Cirjan Dragos
No Comments

Post a Comment