Outputting random array entires

This is a discussion on Outputting random array entires within the C++ Programming forums, part of the General Programming Boards category; Hi, i have an array (of chars, if it matters) and i basically want to extract random entries from them ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    21

    Outputting random array entires

    Hi, i have an array (of chars, if it matters) and i basically want to extract random entries from them for output to the screen, any ideas ?

    Any help appreciated.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    65
    #include <ctime>
    #include <cstdlib>
    #include <iostream>
    using namespace std;

    main()
    {

    char array[20];
    // initialize the array with values you want.
    .
    .
    .
    .
    srand (time(NULL));

    for (i = 1; i <= 5; i++)
    cout << array[rand() % 20];

    return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Random number array
    By matt_570 in forum C++ Programming
    Replies: 12
    Last Post: 11-13-2008, 03:44 PM
  2. Problem Outputting Array Element
    By bulletbutter in forum C++ Programming
    Replies: 6
    Last Post: 04-22-2008, 03:51 PM
  3. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  4. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 12:01 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM

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