Thread: rand() function on a file..!!

  1. #1
    Registered User
    Join Date
    Mar 2012
    Location
    Bangalore
    Posts
    3

    rand() function on a file..!!

    Is it possible to use rand() function on a txt file that i have used in a program??If so, how?

    the file consists of a set of words out of which i want to select a random word every time the program is executed.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Read the file into an array of words.
    Pick a random subscript to get your random word.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-14-2011, 08:08 AM
  2. rand() function
    By thunderzone in forum C Programming
    Replies: 10
    Last Post: 05-02-2010, 07:09 AM
  3. rand() function
    By jduke44 in forum C Programming
    Replies: 9
    Last Post: 10-07-2005, 05:33 PM
  4. rand() function?
    By s_ny33 in forum C++ Programming
    Replies: 2
    Last Post: 03-08-2005, 07:58 PM
  5. Rand() function
    By Da-Nuka in forum C++ Programming
    Replies: 10
    Last Post: 12-26-2004, 08:12 AM