RegEx isn't really used for what you're talking about.

You should use ascii codes to create your alphanumeric array and then choose random indexes from it to create your random string.

var i:int;
var alphaNumeric:Array = [];
for (i = 97; i < 123; ++i)
{
    alphaNumeric.push(String.fromCharCode(i));
    alphaNumeric.push(String.fromCharCode(i - 32));
}
for (i = 0; i < 10; ++i)
{
    alphaNumeric.push(i);
}
function getRandomString(i:int):String
{
    var str:String = "";
    while (i--)
    {
        str += alphaNumeric[Math.round(Math.random() * 62)];
    }
    return str;
}

trace(getRandomString(8));
-- lKzU4e0X

It's worth pointing out that Math.random() is merely decent at generating random values. If you really need random values, it is better to use something like the Parker Miller pseudo-random number generator.

http://www.gskinner.com/blog/archives/2008/01/source_code_see.html
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to