Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Labo_09
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int nbFaces;
  14. int nbDes;
  15. Console.Write("Indiquez le nombre de faces que possède les dés ; ");
  16. nbFaces = int.Parse(Console.ReadLine());
  17. Console.Write("Indiquez le nombre de dés ; ");
  18. nbDes = int.Parse(Console.ReadLine());
  19.  
  20. int nbDeLancers = LireNombreDeLancers();
  21. Console.WriteLine("le blabla est {0}", nbDeLancers);
  22. CréerDistribution(nbDes, nbFaces);
  23.  
  24. Random generateur;
  25. generateur = new Random();
  26. double nbGenere = generateur.NextDouble();
  27.  
  28. int[,] distribution = CréerDistribution(nbDes, nbFaces);
  29.  
  30. AfficherDistribution(distribution, nbDeLancers);
  31. }
  32. static int LireNombreDeLancers()
  33. {
  34. int nbDeLancers;
  35. const int MAX_LANCER = 10000;
  36. const int MIN_LANCER = 500;
  37. Console.WriteLine("Combien de lancers y aura-t-il? (Entre 500 et 10 000) : ");
  38. nbDeLancers = int.Parse(Console.ReadLine());
  39. while (nbDeLancers <= MIN_LANCER || nbDeLancers >= MAX_LANCER)
  40. {
  41. Console.WriteLine("La valeur doit être entre 500 et 10000");
  42. nbDeLancers = int.Parse(Console.ReadLine());
  43.  
  44. }
  45. return nbDeLancers;
  46.  
  47. }
  48. static int[,] CréerDistribution(int nbDes, int nbFaces)
  49. {
  50. int[,] distribution = new int[nbDes, nbFaces];
  51.  
  52. int cpt = 1;
  53. for(int numDes = 0; numDes < distribution.GetLength(1); numDes++)
  54. {
  55. for(int numFaces=0; numFaces< distribution.GetLength(0); numFaces++)
  56. {
  57. distribution[numDes, numFaces] = cpt;
  58. cpt++;
  59. }
  60. }
  61. return distribution;
  62. }
  63. static void SimulerLancerDesDes(int nbDes, int nbFaces, int[,] distribution, int nbLancers, Random generateur)
  64. {
  65. int somme;
  66. for (int i = 0; i < nbLancers; i++)
  67. {
  68. somme = RoulerDes(nbDes, nbFaces, generateur);
  69. distribution[somme-nbDes] += 1;
  70. }
  71.  
  72. }
  73. static int RoulerDes(int nbDes, int nbFaces, Random generateur)
  74. {
  75. int somme = 0;
  76.  
  77. for (int numLancer = 0; numLancer < nbDes; numLancer++)
  78. {
  79. int resultat = RoulerDe(nbFaces, generateur);
  80. somme = somme + resultat;
  81. }
  82. return somme;
  83. }
  84. static int RoulerDe(int nbFaces, Random generateur)
  85. {
  86. const int BORNE_MIN = 1;
  87. int borneMax = nbFaces + 1;
  88. int resultat = generateur.Next(BORNE_MIN, borneMax);
  89. return resultat;
  90. }
  91.  
  92. static void AfficherDistribution(int[,] distribution, int nbLancers)
  93. {
  94. const int MAX = 100;
  95. const int NB_DE_DES = 2;
  96. const int NB_DE_FACES = 6;
  97.  
  98. Console.WriteLine($"Distribution de {nbLancers} lancers de {NB_DE_DES} dés à {NB_DE_FACES} faces");
  99. for(int i = 0; i < distribution.Length; i++)
  100. {
  101. double proportion = distribution[i] / nbLancers;
  102. string histogramme = CreerBarreHistogramme(MAX, proportion);
  103. Console.WriteLine("Somme des dés : {NB_DE_DES} proportion {proportion} % = {histogramme}");
  104.  
  105. }
  106.  
  107. }
  108. static string CreerBarreHistogramme(int max, double proportion)
  109. {
  110. return new string('#', (int)Math.Round((max * proportion), 0, MidpointRounding.AwayFromZero));
  111. }
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement