Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts

    Question Unique random numbers in an array

    Hello, everyone.

    I've got some code that works, but it's slow. Every page refresh is taking 2-4 seconds, which is really bad when you consider that my CF server is the same machine that I'm developing on.

    If anyone could suggest how to speed this up, it would be appreciated.

    Code:
    VARIABLES.rcpi_count = val(ram_cfrt_path_imgs.recordCount);// currently 16
    VARIABLES.rndInt = ArrayNew(1);
    VARIABLES.loopLimit = 4;
    
    do{
      thisInt = RandRange(1,VARIABLES.rcpi_count);
      if(NOT ArrayFind(VARIABLES.rndInt,thisInt){
        ArrayAppend(VARIABLES.rndInt,thisInt);
        }
      }
    while(ArrayLen(VARIABLES.rndInt) LT 4);
    writeDump(VARIABLES.rndInt) abort;
    Thank you,
    Last edited by WolfShade; 04-23-2013 at 01:50 PM.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    I got it working, but it's slow. Any suggestions on how to speed it up?

    Code:
    VARIABLES.rcpi_count = val(ram_cfrt_path_imgs.recordCount);
    VARIABLES.rndInt = ArrayNew(1);
    VARIABLES.loopLimit = 4;
    do{
      thisInt = RandRange(1,VARIABLES.rcpi_count);
      if(NOT ArrayFind(VARIABLES.rndInt,thisInt){
        ArrayAppend(VARIABLES.rndInt,thisInt);
        }
      }
    while(ArrayLen(VARIABLES.rndInt) LT VARIABLES.loopLimit);
    writeDump(VARIABLES.rndInt) abort;
    Thank you,
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •