lundi 1 janvier 2018

how to make a random int value in c for coin flipping

How do I make a random integer value in C? I need it to act like a coin flipping. Here is what I've tried:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <time.h>

int main(void)
{
int i;

srand(time(NULL));

for (i=0; i<10; i++)
    if ((int)(((float) rand() / ((float) SHRT_MAX)) * 2) > 0)
        puts("etz");
    else
        puts("pali");
return EXIT_SUCCESS;
}




Aucun commentaire:

Enregistrer un commentaire