rand() function on a file..!!

This is a discussion on rand() function on a file..!! within the Game Programming forums, part of the General Programming Boards category; Is it possible to use rand() function on a txt file that i have used in a program??If so, how? ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-14-2011, 07: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, 06:58 PM
  5. Rand() function
    By Da-Nuka in forum C++ Programming
    Replies: 10
    Last Post: 12-26-2004, 07:12 AM

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