srand() or rand()???

This is a discussion on srand() or rand()??? within the C Programming forums, part of the General Programming Boards category; hi there, I am writing a game that is suppose to have a dice in it. In this program there ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    11

    srand() or rand()???

    hi there,
    I am writing a game that is suppose to have a dice in it. In this program there are 2 players and i want each of them to spin the dice and get different numbers.
    My question is, do you u think that it is better to use rand() or srand() to represent the dice. I was thinking that if you use the rand() function that both players would get the same numbers all the time. What do you think.
    Thanks in advance

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Well, you should use both. Read about random number generation here.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    srand() is used to ensure that everytime you run the program that the numbers generated will be unique each run (in theory). rand() is used to generate the random number.
    Have a look at the functions from here...
    http://www.cprogramming.com/function.html
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    beaten by pianorain
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    11
    Thanks alot for both your help

Popular pages Recent additions subscribe to a feed

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