Thread: Creating a random number generator for input file

  1. #1
    Registered User
    Join Date
    Mar 2016
    Posts
    6

    Creating a random number generator for input file

    Hi everyone. I have an assignment for my C++ course, where we have to make a word guessing game that reads from an input file. The file needs to contain 25 words, with a minimum of six letters. I have finished my input file, with 5 words with a length of 6 letters at the top, and adding a letter for each word in the next 5, down to line 25 (6 letter words for first 5 lines, 7 letter words for next 5 lines, etc). We are required to take the user's input to determine how many letters they want the word to contain, and then choose a random word in the file based on their input. How do I make a random number generator to make sure it goes to the right line in the file for the correct word length? I was thinking of using a modulus operator, but I'm not sure that would work. If I'm not making sense, please let me know. I'm brand new to C++, so I'm a little over my head with this.
    Last edited by JCampCode30; 10-10-2016 at 09:34 AM.

  2. #2
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    If you have access to C++11, you can try this: std::uniform_int_distribution - cppreference.com

    Or, you can do this: http://www.cplusplus.com/reference/cstdlib/rand/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Random Number Generator Stuck on 1 Number?
    By Dollydaydream in forum C++ Programming
    Replies: 3
    Last Post: 11-26-2013, 08:43 AM
  2. Replies: 5
    Last Post: 04-17-2012, 04:52 PM
  3. need a random number generator thats not compleatly random
    By thedodgeruk in forum C++ Programming
    Replies: 1
    Last Post: 06-05-2011, 06:48 AM
  4. A new random number generator!
    By Sebastiani in forum General Discussions
    Replies: 19
    Last Post: 07-30-2009, 03:27 PM
  5. Random Number Generator
    By Ikurik in forum C++ Programming
    Replies: 16
    Last Post: 08-17-2003, 07:34 PM

Tags for this Thread