fork(6) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5.  
  6.  
  7.  
  8. int rand_a_b(int min,int max){
  9.  
  10. return rand()%(max-min)+min;
  11. }
  12.  
  13.  
  14. char getLettreRandom(int nombreAleatoire)
  15. {
  16. // Tirage de lettre en fonction de sa probabilité d'apparaitre dans un corpus donné de 1 486 104 lettres
  17. // Source wiki.
  18.  
  19.  
  20.  
  21. // On fait correspondre les occurrences avec les lettres.
  22. int occurrences[] = {225947, 121895, 117110,115465,111103,108812,100500,96785,83668,
  23. 82762,56269,50003,46335,45521,24975,20889,16351,13822,11298,
  24. 8351,5928,4725,2093,1747,745,695,283,};
  25. char lettres[] = "esaitnrulodcpmvqfbghjxyzwk";
  26.  
  27.  
  28. int i, total;
  29.  
  30. char retour = ' '; /* Valeur par défaut au cas où */
  31. for (i=0, total = 0; i < 26; i++)
  32. {
  33. if ( (nombreAleatoire > total) && (nombreAleatoire < total + occurrences[i]))
  34. {
  35. retour = lettres[i];
  36. break;
  37. }
  38. total += occurrences[i];
  39. }
  40. return retour;
  41. }
  42.  
  43.  
  44.  
  45. int main(){
  46.  
  47.  
  48. srand(time(NULL));
  49.  
  50. char c , d, e = ' ';
  51. c= getLettreRandom(rand_a_b(0,1486104));
  52. d= getLettreRandom(rand_a_b(0,1486104));
  53. e= getLettreRandom(rand_a_b(0,1486104));
  54.  
  55. printf("%c\n %c\n %c\n",c,d,e);
  56.  
  57.  
  58.  
  59.  
  60. }
  61.  
Runtime error #stdin #stdout 0s 2296KB
stdin
Standard input is empty
stdout
a
 i
 o