Untitled
namespace ConsoleApp3 { internal class Program { static void Main(string[] args) { Random random = new Random(); string[] examples = new[] { "example_1", "example_2", "example_3", "example_4", "example_5", "example_6", "example_7", "example_8", "example_9", "example_10", }; List<int> nums = new List<int>(); Console.WriteLine("Введите количество нужных случайных значении: "); int input = Convert.ToInt32(Console.ReadLine()); int randomIndex = -1; int i = 0; while(i < input) { randomIndex = random.Next(examples.Length); if (nums.Contains(randomIndex)) { continue; } else { Console.WriteLine(examples[randomIndex]); nums.Add(randomIndex); i++; } } //int randomIndexBefore = 0; //int randomIndexAfter = -1; //int i = 0; //while (i < 3) //{ // randomIndexBefore = random.Next(examples.Length); // 5, 3 // if (randomIndexBefore != randomIndexAfter) // { // Console.WriteLine(examples[randomIndexBefore]); // randomIndexAfter = randomIndexBefore; // 5 // i++; // } // else // { // continue; // } //} } } }
Leave a Comment