1. Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Rep Power

    Question return random symbol &\ or number?

    How do I get a program to return a random Symbol (%*&+-) etc. and/or numbers from a given set (2 4 6 8) to a user?

    I'm using Visual c++ on XP.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Rep Power
    ...by getting a random number over the range of the array index values containing the symbols.

    #include <cstdlib>
    #include <ctime>

    //seed the random number generator with time() function
    srand(static_cast<unsigned>( time(0)));

    //generate random number from 0 to count-1

    //Function to generate a random integer 0 to count -1
    int random(int count)
    return static_cast<int>((count*static_cast<long>(rand()))/(RAND_MAX+1));

    From Ivor Horton's Beginning C++ 6.
    Last edited by 7stud; March 3rd, 2003 at 03:17 AM.

IMN logo majestic logo threadwatch logo seochat tools logo