LunaticThinker.me

Thoughts on code and poetry.

Welcome to LunaticThinker.me - thoughts on code and poetry.

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.


    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;
    }

Dumping Object Inside Cfscript Tag

I’ve been looking for this a few times now, until now i’ve found two interesting options.

One is creating a cffunction of your own, and using it inside a cfscript afterwards:


    
    

The other one is using a 100% cfscript approach, which can also be placed in a function of your own:

createObject("component", "cfide.adminapi.base").dump(var);

Also, starting ColdFusion 9, you can use the writeDump function.

0%