jeudi 6 mai 2021

C# Randomly pick value from table with specify pattern

I would like to have 4 list of data which are 12 randomly picked data on each row in those table with a designated pattern of "*".

I did try use Random() function but it was not working as the desire output.

Below are my sample code :

for (int i = 0; i < dgvA1.Rows.Count; i++)
                {
                    int row = 0; int col = 0;

                    //Get First Row
                    for (int x = 0; x < 12;x++)
                    {
                        Random r = new Random();
                        int randomNumber = r.Next(1, 35); //for ints
                        row = randomNumber;
                        col = randomNumber;
                        rbLog.Text += row.ToString() + ";" + col.ToString();
                    }
                }

Below are the picture of the table, and the red line are the coordinate that i wanted to be randomly selected on each of the line. enter image description here

Total will be 4 line of random picked with 12 data each line. Any other method or linQ can done that?

Thanks




Aucun commentaire:

Enregistrer un commentaire