this was a quiz question on cf weekly
    http://coldfusionweekly.com/index.cfm?event=showCFQuiz

Version 2.13 – April 23, 2007
there are 6 responces thst you can review


On 7/26/07, Maximilian Nyman <[EMAIL PROTECTED]> wrote:
>
> You don't actually need to use the StructKeyExists though
> I would take what Russ said and rewrite the function to this:
>
> function getRandomNumberArray(length, count) {
> var min = "1" + repeatString("0", length - 1);
> var max = repeatString("9", length);
> var uniquer = structNew();
> while (structCount(uniquer) LT count) {
>    uniquer[randRange(min, max)] = "";
> }
> return StructKeyArray(uniquer);
> }
>
> Or you could return the StructKeyList(uniquer), if you rather have the
> Random numbers in  a list
>
> /Max
>
> On 7/26/07, Ben Nadel <[EMAIL PROTECTED]> wrote:
> > Barney, I love the 1XYZ-N technique for the length constraint That's
> > damn brilliant!
> >
> > ......................
> > Ben Nadel
> > Certified Advanced ColdFusion MX7 Developer
> > www.bennadel.com
> >
> > Need ColdFusion Help?
> > www.bennadel.com/ask-ben/
> >
> > -----Original Message-----
> > From: Barney Boisvert [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, July 25, 2007 6:01 PM
> > To: CF-Talk
> > Subject: Re: Generate Random Number 1000 - No Duplicates
> >
> > I haven't tested this (just wrote it in the email), but it should be
> > close:
> >
> > function getRandomNumberArray(length, count) {
> >   var min = "1" + repeatString("0", length - 1);
> >   var max = repeatString("9", length);
> >   var uniquer = structNew();
> >   var result = arrayNew(1);
> >   var num = "";
> >   while (arrayLen(result) LT count) {
> >     num = randRange(min, max);
> >     if (NOT structKeyExists(uniquer, num)) {
> >       uniquer[num] = "";
> >       arrayAppend(result, num);
> >     }
> >   }
> >   return result;
> > }
> >
> > cheers,
> > barneyb
> >
> >
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion is delivering applications solutions at at top companies 
around the world in government.  Find out how and where now
http://www.adobe.com/cfusion/showcase/index.cfm?event=finder&productID=1522&loc=en_us

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:284606
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to