1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Rand,srand and sleep in C

  1. Aug 8, 2011 #1
    in C how can one use rand,srand and sleep functions...
    also what type of random numbers are generated by rand & srand.?

  2. jcsd
  3. Aug 8, 2011 #2
    Last edited by a moderator: Apr 26, 2017
  4. Aug 9, 2011 #3

    Never heard of sleep function before!

    rand will return a integer in the range 0 to RAND_MAX in the form of for example:

    int rnumber;
    rnumber=rand()%6; ---->this will give you a random number between 0 and 5
    rnumber=rand()%6+1; ---->this will give you a random number between 0 and 6

    This is great, the problem with this function alone is that it just gives you back a number of a already non-changing seed, if im not mistaken!
    To constantly change the seed you need to implement something in the begining which i dont really remember what it is!

    Also srand() function is best for lets say, a study on the results of a average number that gets out of a dice!

    I was writing one program to make that several times by calling a function a several number of times to get a very precise result!

    But im rusty in C languagem although im studying a little this vacations!
    Last edited by a moderator: Apr 26, 2017
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook