Heh, but if you're REALLY going for unreadable lines of code, you might as well go all the way:
function repeat(n:Number, f:Function) : Array { return n > 1 ? repeat(n-1, f).concat(f()) : [f()]; } function createUID():String { return repeat(4, function(){ return repeat(3, function(){ return String("BCDFGHJKLMNPQRSTVWXYZ").substr(int(Math.random()*19), 1) }).join("") }).join("-"); } On Mon, Jan 5, 2009 at 6:12 PM, Josh McDonald <dzn...@gmail.com> wrote: > A quick take on it: > > function randomLetter() : String > { > const noVowels : String = "BCDFGHJKLMNPQRSTVWXYZ"; > return noVowels.charAt(Math.round(Math.random() * > (noVowels.length - 1))); > } > > function repeat(n : Number, f : Function) : Array > { > return n > 1 ? repeat(n-1, f).concat(f()) : [f()]; > } > > var result : String = repeat(4, function() : String { > return repeat(3, randomLetter).join(""); }).join("-"); > > -Josh > > > On Tue, Jan 6, 2009 at 11:45 AM, anuj sharma <anuj...@gmail.com> wrote: > >> Hi Brendan >> makes sense to put the code :-), With the format I was looking for >> following code works perfectly for me, I am not sure thats the right way of >> coding but this is working for my purpose. I am pretty sure there can be far >> far better way for this >> Anuj >> /**************************CODE******************/ >> <mx:Script> >> <![CDATA[ >> import mx.messaging.channels.StreamingAMFChannel; >> import mx.controls.Alert; >> >> [Bindable] >> public var track:String; >> private function init():void >> { >> btn_genkey.addEventListener(MouseEvent.CLICK,key); >> } >> >> >> public function key(event:MouseEvent):void >> { >> var newLength:uint = 12; >> var userAlphabet:String = "BCDFGHJKLMNPQRSTVWXYZ"; >> var alphabet:Array=userAlphabet.split(""); >> var alphabetLength:int = alphabet.length; >> var randomLetters:String = ""; >> >> var _keyfirstpart:String; >> var _keysecondpart:String; >> var _keythirdpart:String; >> var _keyforthpart:String; >> var _concatenatedString:String; >> for (var i:uint = 0; i < newLength; i++) >> { >> randomLetters += alphabet[int(Math.floor(Math.random() * >> alphabetLength))]; >> } >> _keyfirstpart=randomLetters.slice(0,3); >> _keysecondpart=randomLetters.slice(3,6); >> _keythirdpart=randomLetters.slice(6,9); >> _keyforthpart=randomLetters.slice(9,12); >> >> >> _concatenatedString=_keyfirstpart+"-"+_keysecondpart+"-"+_keythirdpart+"-"+_keyforthpart; >> text_ii.text=_concatenatedString; >> >> } >> ]]> >> </mx:Script> >> >> <mx:TextInput id="text_ii" x="645" y="270" width="224"/> >> <mx:Button id="btn_genkey" x="513" y="270" label="Generate key" >> width="124" /> >> >> >> >> On Mon, Jan 5, 2009 at 5:39 PM, Brendan Meutzner <bmeutz...@gmail.com>wrote: >> >>> So what did you end up putting together? Should post the code here >>> for the next guy... >>> >>> >>> Brendan >>> >>> >>> >>> On Mon, Jan 5, 2009 at 5:41 PM, anuj sharma <anuj...@gmail.com> wrote: >>> >>>> Awesome guys your guidance help me in achieving this withing 30 >>>> minutes, it is working now >>>> Thanks for your help again >>>> Anuj >>>> >>>> On Mon, Jan 5, 2009 at 2:19 PM, anuj181 <anuj...@gmail.com> wrote: >>>> >>>>> Hi >>>>> I need to work on a piece of code in which whenever user clicks on the >>>>> button , the code should generate random 12 character key having all >>>>> caps and no vowels in the format of XXX-XXX-XXX-XXX. Can anybody guide >>>>> me in this direction. Is there any built in function for that or do I >>>>> have to use my own logic for random generation in this specific case. >>>>> Any help will be appreciated. >>>>> Thanks >>>>> Anuj >>>>> >>>>> >>>> >>> >>> >>> -- >>> Brendan Meutzner >>> http://www.meutzner.com/blog/ >>> >> >> > > > -- > "Therefore, send not to know For whom the bell tolls. It tolls for thee." > > Like the cut of my jib? Check out my Flex blog! > > :: Josh 'G-Funk' McDonald > :: 0437 221 380 :: j...@gfunk007.com > :: http://flex.joshmcdonald.info/ > :: http://twitter.com/sophistifunk > >