Random integer (1-10)

This is a discussion on Random integer (1-10) within the C++ Programming forums, part of the General Programming Boards category; I was wondering how to use the Rand feature ( i think that is what it is called) to make ...

  1. #1
    Registered User Zenomori's Avatar
    Join Date
    Apr 2005
    Location
    Hinesville, GA
    Posts
    3

    Random integer (1-10)

    I was wondering how to use the Rand feature ( i think that is what it is called) to make an integer randomize from 1 to 10. ( im a beginner at this)

    P.S If Someone could point me in the direction of a good starter book that would be awesome!

  2. #2
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    rand()%10 + 1

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    seed your random number generator:
    Code:
    srand(time(NULL));   // do this once per run of the program

    then you can do this:
    Originally posted by Lithorien
    Code:
    rand()%10 + 1


    vvv And here are some books vvv
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  4. #4
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    907
    And read the FAQ. (Or the tutorial?)
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  5. #5
    Registered User osolis's Avatar
    Join Date
    Apr 2005
    Posts
    4
    A C++ book i think is awesome is "C++ Programming: from problem analysis to program design" i borrowed the book from someone who is taking a CSCI class the book is pretty expensive though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  2. Array help
    By Oklaskull in forum C Programming
    Replies: 19
    Last Post: 03-11-2008, 04:15 PM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM
  4. problem with random integer
    By techno logic in forum C++ Programming
    Replies: 1
    Last Post: 10-07-2002, 02:20 PM
  5. Best way to generate a random double?
    By The V. in forum C Programming
    Replies: 3
    Last Post: 10-16-2001, 04:11 PM

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