# Rand,srand and sleep in C

1. Aug 8, 2011

### the_kool_guy

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

thanks

2. Aug 8, 2011

### MisterX

Last edited by a moderator: Apr 26, 2017
3. Aug 9, 2011

### kalakoi

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