n00b question

This is a discussion on n00b question within the C++ Programming forums, part of the General Programming Boards category; How do you generate a random number?...

  1. #1
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942

    Question n00b question

    How do you generate a random number?

  2. #2
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942

    Sorry

    hit submit twice

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    Code:
    int number = rand();

  4. #4
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001
    Posts
    196
    ok

    Code:
    #include <time.h>
    
    int main()
    {
    srand(time(0)); // seed it
    
    int x = (rand() % (100 - 1 + 1) ) + 1;
    
    return 0;
    }
    the equation for random number is
    (rand() % (high - low + 1)) + low
    nextus, the samurai warrior

  5. #5
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    I wrote a tutorial on this on the mainpage, perhaps you should look before you leap?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another n00b question: storing text as a variable
    By Jmcrofts in forum C++ Programming
    Replies: 1
    Last Post: 07-29-2007, 08:12 AM
  2. Very sorry, but this must be the most n00b question =]
    By Teh_n00b in forum C++ Programming
    Replies: 24
    Last Post: 01-23-2007, 06:46 PM
  3. n00b question... deleting an object
    By revelation437 in forum C++ Programming
    Replies: 6
    Last Post: 05-05-2003, 07:39 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM

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