Results 1 to 3 of 3

Thread: speed up the program

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Posts
    5

    Post

    Do you have any idea to reduce the time on generate a large ammount(e.g > 10000) of random number into array?

    My code is :
    dim temp as long
    dim arr() as long
    dim maxvalue as long

    redim arr(1 to x)
    For temp=1 to x
    arr(temp) = int(rnd*maxvalue)+1
    next temp
    .
    .
    .
    is it possible to speed up the program??


  2. #2
    Guest

    Post

    Assuming that you need a random number and are storing in an array for future referencing:

    You could make a private function that generates the number, then the first time you need that number save it to the array for future use.

    This will appearingly cut your time making the processing as close to parallel as possible.

    Example:

    Loop
    'Process
    'I need a random number
    Get_Rand
    'save number to array
    'continue processing
    end loop

    Function Get_Rand()
    'Generate random nummber
    End

  3. #3
    Member
    Join Date
    Feb 2000
    Location
    Toronto, Canada
    Posts
    44

    Post

    [QUOTE][B]
    Oneway is to reduce the amount of variables in your loop. Instead of x use 100000 and maxvalue use a number.

    If you want a random number less than 36000 then define ARR as an integer.

    It is faster for VB to store integers than long numbers


    Edited by Sacred_knight on 02-23-2000 at 11:18 AM

Posting Permissions

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



Click Here to Expand Forum to Full Width