mardi 24 septembre 2019

Need help implementing total random characters in C

I am creating a program that prints out 1000 random occurrences of the letters "H" and "T" and my code implements rand()%2 but as i can see from running this program (code below) that its not completely random (the letters are random but always the same with every execution). I want to establish a more effective way by implementing RANDMAX to make every case of the program running completely random, how would I be able to do this?

#include <stdio.h>
#include<stdlib.h>

int main()
{
  int i=1,n;
  char ch ;
    for( i = 1; i <= 1000 ; i ++ )
    {
     n = rand()%2;
     if(n==0)
       ch = 'T';
     else
       ch = 'H';
       putchar(ch);
     }
      return 0;
  }



Aucun commentaire:

Enregistrer un commentaire