Random generated String


/ Published in: ActionScript 3
Save to your folder(s)

This is easy way to generate random string

this will generate random word with 10 letters in it
var a:String = randString(10);


Copy this code and paste it in your HTML
  1. public function randString(_length:Number = 10):String{
  2. var alphabet:String = "qwertyuiopasdfghjklzxcvbnm123456789QWERTYUIOPASDFGHJKLZXCVBNM";
  3. var temp:Array = alphabet.split("");
  4. var tempString:String = "";
  5.  
  6. for(var i:Number = 0; i<_length; i++){
  7. tempString+= temp[ Math.ceil( Math.random()*alphabet.length - 1 )]
  8. }
  9.  
  10. return tempString;
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.