ajout d'un programme c simple pour renvoyer 0 ou 1 en valeur de retour
parent
4be5ac0776
commit
df126bcba6
@ -0,0 +1,6 @@
|
|||||||
|
all: build
|
||||||
|
|
||||||
|
build: random
|
||||||
|
|
||||||
|
random: main.c
|
||||||
|
gcc main.c -Wall -o random
|
@ -0,0 +1,31 @@
|
|||||||
|
#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;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue