Quick question.. why does rand() keep giving me the same 'random' number each time?

This is a discussion on Quick question.. why does rand() keep giving me the same 'random' number each time? within the C++ Programming forums, part of the General Programming Boards category; Hey again everyone I was doing the tuts and problem solving question things on this site and came across the ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Location
    Tamworth, NSW, Australia
    Posts
    16

    Quick question.. why does rand() keep giving me the same 'random' number each time?

    Hey again everyone

    I was doing the tuts and problem solving question things on this site and came across the guessing game. I did it all and it's working as needed, but every time I run it, rand()%100; always gives me the result 41??
    Why?

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,804
    Did you seed the random number generator with srand()?

    Jim]

  3. #3
    Registered User
    Join Date
    Sep 2011
    Location
    Tamworth, NSW, Australia
    Posts
    16
    No. I just copied the code from the website. I haven't really ever had anything to do with rand() as the temp software I write doesn't ever need random numbers. But thank you, I will look into that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Random number<-time.h
    By Wingless in forum C Programming
    Replies: 3
    Last Post: 11-03-2010, 03:57 AM
  2. rand() function giving same number repeatedly
    By Adam_H in forum C Programming
    Replies: 2
    Last Post: 11-15-2009, 08:43 AM
  3. Random rand() question
    By Nathan the noob in forum C++ Programming
    Replies: 13
    Last Post: 01-27-2009, 12:52 PM
  4. Making A Random Number Each Time?
    By relyt_123 in forum C++ Programming
    Replies: 6
    Last Post: 07-28-2006, 03:16 PM
  5. HELP! My rand() won't make a random number...
    By Budgiekarl in forum C Programming
    Replies: 2
    Last Post: 05-18-2003, 08:11 PM

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