Thread: rand() doesn't randomize

  1. #1
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408

    rand() doesn't randomize

    In a little mini game i have made i use some rand() % blabla to check if you hit an enemy or not and for some other things aswell. But each time i run the program the same things happen in the same order.
    Why?

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    You neet to call srand() to seed the random number sequence.

    Refer to FAQs

  3. #3
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    put randomize();

    before the main body/loop..
    -

  4. #4
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Big thanks Fordy!

  5. #5
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    heyy!! you didn't thank me??
    -

  6. #6
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    ThisPost = ignore();
    Last edited by ErionD; 03-14-2002 at 05:28 AM.

  7. #7
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Hehe =)
    Well first of all you posted while i was writing the thank you reply so i didnt know that you had replied.
    Second you didn't provide such a good explanation.
    What happens if i put randomize() before the main()?

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    >>What happens if i put randomize() before the main()?

    Likely that your code will not compile.........

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. randomize array blackjack c program
    By bazzano in forum C Programming
    Replies: 4
    Last Post: 09-01-2005, 02:05 PM
  2. don't want to randomize two alike numbers
    By randomizer in forum C++ Programming
    Replies: 8
    Last Post: 05-26-2005, 07:42 PM
  3. randomize hex digits
    By wazilian in forum C Programming
    Replies: 3
    Last Post: 12-14-2002, 03:20 AM
  4. Problem with Visual C++ ( randomize function )!
    By marCplusplus in forum C++ Programming
    Replies: 2
    Last Post: 12-17-2001, 01:01 PM
  5. Randomize Number Function
    By beyonddc in forum C Programming
    Replies: 3
    Last Post: 12-10-2001, 04:31 AM