arrays of random integers & time

This is a discussion on arrays of random integers & time within the C++ Programming forums, part of the General Programming Boards category; I have two questions out there for those who can respond. 1. How do I create a large array full ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    11

    arrays of random integers & time

    I have two questions out there for those who can respond.

    1. How do I create a large array full of random integers?

    2. How do I call the time so I can use it for checking the speed of a function?

    I would appreciate any and all input.

    meeloff

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,807
    1: Create a large array, use a loop and rand().

    2. Make 2 time variables call time() on one in the begining of the function call the other at the end of the function call difftime on them and store that to a variable
    for time read this http://www.cppreference.com/stddate_...s.html#asctime
    Last edited by prog-bman; 12-07-2004 at 02:57 PM.
    Woop?

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    11
    Something like this:

    Code:
    #include <cstdlib>
    #include <iostream>
    
    void main()
    {
           int i;
           int size = 50;
           int array[size];
    
           srand( (unsigned) time ( NULL ) );
           
           for(i = 0; i < size; i++)
           {
                   array[i] = rand();
            }
    
    }
    I found this on MSDN.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,802
    Code:
    #include <cstdlib>
    #include <ctime>
    #include <iostream>
    
    int main()
    {
           int i;
           const int size = 50;
           int array[size];
    
           srand( (unsigned) time ( NULL ) );
           
           for(i = 0; i < size; i++)
           {
                   array[i] = rand();
            }
    
    }
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help in time zone
    By Gong in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2007, 03:44 AM
  2. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 04:51 PM
  3. The space time continueimnms mm... (rant)
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 06-27-2004, 01:21 PM
  4. Adding arrays of integers in a node struct
    By emilyashu in forum C Programming
    Replies: 7
    Last Post: 04-26-2003, 06:19 PM
  5. inputting time in separate compilation
    By sameintheend01 in forum C++ Programming
    Replies: 6
    Last Post: 03-13-2003, 03:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21