Used with #

How to make randomization carried out in two ways?
Option 1: min = 1,000; max = 5,000; col = 1;
Option 2: min = 1; max = 20; col = 4;

The attached code could not be configured, so I would be grateful if someone would help to customize or offer their own version to solve this problem. Link to the project
reference to the project IZM1
How to download the project see ( http://prntscr.com/dmh2iw )

description

CODE

namespace rsh { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Random r = new Random(); // РАНДОМИЗАЦИЯ ВАРИАНТ 1 private void button1_Click(object sender, EventArgs e) { int min = Convert.ToInt16(textBox1.Text); // МАКС - максимальное число диапазона int max = Convert.ToInt16(textBox2.Text); // МИН - минимальное число диапазона int col = Convert.ToInt16(textBox3.Text); // количество итераций int[] perm = Enumerable.Range(min, max + 1).ToArray(); for (int i = col; i >= 1; i--) { int j = r.Next(i + 1); // exchange perm[j] and perm[i]; int temp = perm[j]; perm[j] = perm[i]; perm[i] = temp; textBox4.AppendText(perm[i] + " " + "\r\n"); // выдаёт ОДИН ряд цифр } } // РАНДОМИЗАЦИЯ ВАРИАНТ 2 private void button3_Click(object sender, EventArgs e) { int min = Convert.ToInt16(textBox1.Text); // МАКС - максимальное число диапазона int max = Convert.ToInt16(textBox2.Text); // МИН - минимальное число диапазона int col = Convert.ToInt16(textBox3.Text); // количество итераций int[] perm = Enumerable.Range(min, max + 1).ToArray(); for (int i = col; i >= 1; i--) { int j = r.Next(i + 1); // exchange perm[j] and perm[i]; int temp = perm[j]; perm[j] = perm[i]; perm[i] = temp; textBox4.AppendText(perm[i] + " " + "\r\n"); // выдаёт ОДИН ряд цифр } } private void button2_Click(object sender, EventArgs e) { textBox4.Clear(); } } } 
  • Please edit your question so that you can highlight the essence and so that it doesn’t look a la "help, it doesn’t work somewhere, but I don’t know where". If the question is about random numbers, then omit the code specific to winforms . - Vadim Ovchinnikov
  • "min = 1,000; max = 5,000; col = 1", what does col mean? step in sequence? - Vadim Ovchinnikov

1 answer 1

The link is your non-working. Here is an example of a console program:

 class Program { static void Main(string[] args) { foreach (var item in GetRandomNumbers(1000, 5000)) { Console.WriteLine(item.ToString()); } Console.WriteLine(new string('=', 20)); foreach (var item in GetRandomNumbers(1, 20)) { Console.WriteLine(item.ToString()); } Console.ReadKey(); } public static List<int> GetRandomNumbers(int min = 0, int max = 5) { if (max - min <= 0) throw new ArgumentException("Неверные аргументы в вызове метода"); int seed = (int)DateTime.Now.Ticks; Random rnd = new Random(seed); List<int> result = Enumerable.Range(min, max).OrderBy(n => rnd.Next()).ToList(); return result; } } 

But I do not quite understand what it means to you: "The attached code could not be configured ..."?