Challeng #2 response (Dice roll game)

0 behnam aghakhanian · August 7, 2015
Here is my response
the question is why the random number is always the same??!!!
and is there any other way to let the user just hit the enter and then receive the random number?? i mean what type of scanf should i write to do that?

/images/forum/upload/2015-08-07/c0c51204c800c55fb3c4f9ec3f4124d3.png

Post a Reply

Replies

Oldest  Newest  Rating
0 Sha Kal · August 7, 2015
Yeah computer decides random numbers before you even start unless you type " srand ( time(NULL) ); "  in your code. Type it only once at the very beginning of your program (below main() ) and...doesnt matter how it works, just type in and its going to give you random numbers :D..


Good job btw!
0 behnam aghakhanian · August 7, 2015
tnx a lot sha :D;)

it worked perfectly.
+1 c student · August 8, 2015
rand uses a mathematical expression to calculate the numbers.  using srand (seed) provides an alteration to this calculation.  if your seed is static (the same every time), so will your rand value.  if your seed is dynamic (constantly changing), so will your rand value.
  • 1

C

106,928 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator