You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
498 B
C
32 lines
498 B
C
#include <time.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
/**
|
|
* Return a random number between 0 and limit inclusive.
|
|
*
|
|
*/
|
|
int rand_lim(int limit) {
|
|
|
|
int divisor = RAND_MAX/(limit+1);
|
|
int retval;
|
|
|
|
do {
|
|
retval = rand() / divisor;
|
|
} while (retval > limit);
|
|
|
|
return retval;
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
srand(time(NULL));
|
|
|
|
int random_value = rand_lim(1);
|
|
|
|
printf("value: %d\n", random_value);
|
|
|
|
//return rand_lim(1);
|
|
return random_value;
|
|
};
|
|
|