Thanks Juan, Thanks Jim.
@Steve
I noticed with your example I get "undefined" as one of the results.
Also, I had to change the var i:int; to var i:number = 0;
I got an error with int saying it could not load the class or
interface for int.
What am I missing here?
TIA
Karl
On Jun 17, 2010, at 9:28 AM, Juan Pablo Califano wrote:
If don't want to learn the ascii codes by heart (or look them up),
you can
use charCodeAt() like this:
var first:int = ("A").charCodeAt(0);
var last:int = ("Z").charCodeAt(0);
for (var i:int = first; i <= last; i++) {
trace(String.fromCharCode(i));
}
Cheers
Juan Pablo Califano
2010/6/17 Karl DeSaulniers <[email protected]>
Ah thanks Steve.
So is 97 to 123 the placement of upper and lowercase letters and the
numbers on the CharCode chart?
and are the upper and lowercase letters 32 letters apart on the
chart?
Trying to understand where you got these values. Your solution is
very good
and interesting to me.
Also, why random off of 62? Is that the total characters in the array
alphaNumeric?
Thank you for this.
Karl
On Jun 17, 2010, at 12:57 AM, Steven Sacks wrote:
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
Karl DeSaulniers
Design Drumm
http://designdrumm.com
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Karl DeSaulniers
Design Drumm
http://designdrumm.com
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders