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



int rand_a_b(int min,int max){

    return rand()%(max-min)+min;
}


char getLettreRandom(int nombreAleatoire)
    {
		// Tirage de lettre en fonction de sa probabilité d'apparaitre dans un corpus donné de 1 486 104 lettres
		// Source wiki.



		// On fait correspondre les occurrences avec les lettres.
       int occurrences[] = {225947, 121895, 117110,115465,111103,108812,100500,96785,83668,
							82762,56269,50003,46335,45521,24975,20889,16351,13822,11298,
							8351,5928,4725,2093,1747,745,695,283,};
       char lettres[] = "esaitnrulodcpmvqfbghjxyzwk";


       int i, total;

       char retour = ' '; /* Valeur par défaut au cas où */
       for (i=0, total = 0; i < 26; i++)
       {
           if ( (nombreAleatoire > total) && (nombreAleatoire < total + occurrences[i]))
           {
                 retour = lettres[i];
                 break;
           }
           total += occurrences[i];
       }
       return retour;
    }



int main(){


	srand(time(NULL));

	char c , d, e = ' ';
	c=	getLettreRandom(rand_a_b(0,1486104));
		d=	getLettreRandom(rand_a_b(0,1486104));
			e=	getLettreRandom(rand_a_b(0,1486104));
			
	printf("%c\n %c\n %c\n",c,d,e);



	getchar();

}
