The document contains C# code that generates random numbers and passwords. It creates a Random object and uses its Next method to generate random integers and pick characters from a string to create a random password between half the maximum length and the maximum length. It outputs the generated password.
The document contains C# code that generates random numbers and passwords. It creates a Random object and uses its Next method to generate random integers and pick characters from a string to create a random password between half the maximum length and the maximum length. It outputs the generated password.
The document contains C# code that generates random numbers and passwords. It creates a Random object and uses its Next method to generate random integers and pick characters from a string to create a random password between half the maximum length and the maximum length. It outputs the generated password.
int n = gen.Next(); //int m = gen.Next(5, 10); //double d = gen.NextDouble(); //Console.WriteLine("n = {0}, m = {1}, d = {2}", n, m, d); //Console.Write("Donner le nombre d'entiers à tirer: "); //int max = int.Parse(Console.ReadLine()); //int n1 = 0, n2 = 0, n3 = 0, n4 = 0, n5 = 0, n6 = 0; //for(int i = 0;i<max; i++) //{ // int r = gen.Next(1, 7); // if (r == 1) n1++; // else if (r == 2) n2++; // else if (r == 3) n3++; // else if (r == 4) n4++; // else if (r == 5) n5++; // else n6++; //} //Console.WriteLine("n1 = {0}", n1/(float)max); //Console.WriteLine("n2 = {0}", n2 / (float)max); //Console.WriteLine("n3 = {0}", n3 / (float)max); //Console.WriteLine("n4 = {0}", n4 / (float)max); //Console.WriteLine("n5 = {0}", n5 / (float)max); //Console.WriteLine("n6 = {0}", n6 / (float)max);
//2ème Méthode avec Array
//int[] n = new int[6]; //for (int i = 0; i < 6; i++) // n[i] = 0; //for(int i =0;i<max;i++) // n[gen.Next(1, 7) - 1]++; //for (int i = 0; i < 6; i++) // Console.WriteLine("La face {0} est répétée {1} fois.", i + 1, n[i]);
//Prob 3
Console.Write("Donner la valeur maximale de caractères:");
int n = int.Parse(Console.ReadLine()); int m = gen.Next(n / 2, n); string s = "abcdefghijklmnopqrstuvwxyz0123456789"; string motdepasse = ""; while(motdepasse.Length<m) { int r = gen.Next(s.Length); if (motdepasse.Length == 0) motdepasse = s[r].ToString(); else { if (motdepasse[motdepasse.Length - 1] != s[r]) motdepasse += s[r]; } } Console.WriteLine("Le mot de passe sera: {0}", motdepasse); Console.ReadKey();