Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Labo_09
- {
- class Program
- {
- static void Main(string[] args)
- {
- LireValeur(out int NB_LANCERS);
- const int NOMBRE_DÉS = 2;
- const int NOMBRE_FACES = 6;
- // Console.WriteLine($"pour {NOMBRE_DÉS} dés à {NOMBRE_FACES} faces les probabilités sont : ");
- int[] tableauDés = CréerDistribution(NOMBRE_DÉS, NOMBRE_FACES);
- Random générateur = new Random();
- SimulerLancerDesDés(NOMBRE_DÉS, NOMBRE_FACES, tableauDés, NB_LANCERS, ref générateur);
- // Console.WriteLine(tableauDés[0]);
- Console.WriteLine($"pour {NOMBRE_DÉS} dés à {NOMBRE_FACES} faces les probabilités sont : ");
- AfficherDistribution(tableauDés, NB_LANCERS);
- }
- static int [] CréerDistribution( int nombreDés, int nombreFaces)
- {
- int indiceTab;
- indiceTab = nombreDés * nombreFaces - nombreDés + 1;
- int[] tableau;
- tableau = new int[indiceTab];
- return tableau;
- }
- static void LireValeur(out int NB_LANCERS)
- {
- const int NB_LANCERS_MIN = 500;
- const int NB_LANCERS_MAX = 10000;
- bool succes /*= false*/;
- Console.WriteLine("Quel est le nombre de lancers que vous voulez effectuer ([500,10000]) : ");
- //NB_LANCERS = int.Parse(Console.ReadLine());
- succes = int.TryParse(Console.ReadLine(), out NB_LANCERS);
- //Console.WriteLine(succes);
- while ((NB_LANCERS < NB_LANCERS_MIN || NB_LANCERS > NB_LANCERS_MAX) || !succes)
- {
- Console.WriteLine("erreur la valeur doit etre entre 500 et 10000 inclusivement.");
- Console.WriteLine(String.Concat(Enumerable.Repeat("-", 70)));
- Console.WriteLine("Quel est le nombre de lancers que vous voulez effectuer ([500,10000]) : ");
- succes = int.TryParse(Console.ReadLine(), out NB_LANCERS);
- // NB_LANCERS = int.Parse(Console.ReadLine());
- }
- // return NB_LANCERS;
- }
- static void SimulerLancerDesDés(int NOMBRE_DÉS, int NOMBRE_FACES, int[] tableauDés, int NB_LANCERS, ref Random générateur)
- {
- //int VALEUR_MAX_DÉS = NOMBRE_FACES * NOMBRE_DÉS;
- //bool Valeur = false;
- //if (!(Valeur))
- //{
- int valeurAléatoireFinale;
- for (int compteur = 0; compteur < NB_LANCERS; compteur++)
- {
- //Valeur = true;
- valeurAléatoireFinale = RoulerDés(NOMBRE_DÉS, NOMBRE_FACES, ref générateur);
- // Console.WriteLine(valeurAléatoireFinale);
- //introduireDansTab(valeurAléatoireFinale, tableauDés, NOMBRE_DÉS);
- int indiceTab = valeurAléatoireFinale - NOMBRE_DÉS;
- tableauDés[indiceTab] = tableauDés[indiceTab] + 1;
- }
- //}
- }
- static int RoulerDés(int NOMBRE_DÉS, int NOMBRE_FACES, ref Random générateur)
- {
- // int VALEUR_MAX_DÉS = (NOMBRE_FACES * NOMBRE_DÉS);
- int valeurAléatoire1 = RoulerDé(NOMBRE_FACES, NOMBRE_DÉS, ref générateur);
- int valeurAléatoire2 = RoulerDé(NOMBRE_FACES, NOMBRE_DÉS, ref générateur);
- int valeurAléatoireFinale = valeurAléatoire1 + valeurAléatoire2;
- return valeurAléatoireFinale;
- //for (int compteur = 0; tableauDés[compteur] < tableauDés.Length; compteur++)
- //{
- // int valeurAléatoire = générateur.Next(NOMBRE_DÉS, VALEUR_MAX_DÉS);
- // valeurAléatoire
- //}
- //static void SimulerLancerDesDés(int NOMBRE_DÉS, int NOMBRE_FACES, int[] tableauDés, Random générateur)
- //{
- // int VALEUR_MAX_DÉS = NOMBRE_FACES * NOMBRE_DÉS;
- // for (int compteur = 0; tableauDés[compteur] < tableauDés.Length; compteur++)
- // {
- // int valeurAléatoire = générateur.Next(NOMBRE_DÉS, VALEUR_MAX_DÉS);
- // valeurAléatoire
- // }
- }
- static int RoulerDé(int VALEUR_MAX_DÉS, int NOMBRE_DÉS, ref Random générateur)
- {
- int valeurAléatoire = générateur.Next(NOMBRE_DÉS-1, VALEUR_MAX_DÉS+1);
- return valeurAléatoire;
- }
- //static void introduireDansTab(int valeurAléatoireFinale, int[] tableau, int NOMBRE_DÉS)
- //{
- // for (int compteur = 0; compteur < tableau.Length; compteur++)
- // {
- // // int indiceTab = 0;
- // int indiceTab = valeurAléatoireFinale - NOMBRE_DÉS;
- // tableau[indiceTab] = tableau[indiceTab] + 1;
- // }
- //}
- static void AfficherDistribution(int[] tableau, int NB_LANCERS)
- {
- int indiceTab = 0;
- int somme = 2;
- for(int compteur = 0; compteur < tableau.Length; compteur++)
- {
- int MAX = 100;
- double pourcent;
- pourcent = (double)MAX * ( tableau[indiceTab]) / NB_LANCERS;
- Console.WriteLine($"Somme des dés : {somme}, proportion {pourcent:f2}%:{CréerBarreHistogramme(MAX, pourcent)} ");
- ++indiceTab;
- ++somme;
- }
- }
- static string CréerBarreHistogramme(int max, double proportion)
- {
- // on pourrait également le faire avec une boucle for... :/
- return new string('#', (int)Math.Round(
- ( proportion), 0, MidpointRounding.AwayFromZero));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement