lundi 10 mai 2021

how to set up random number generation without remainder?

how can I set my generator random number for division to list only numbers which, when divided, had no remainder? I need only single digit number.

I tried:

 Random druhy = new Random();
            Random prvni = new Random();
            
            int maxprvni = 10;
            int maxdruhy = 10;
            
            int prvnic = prvni.Next(1, maxprvni);
            int druhyc = druhy.Next(2, maxdruhy);
...
if (znamenko.Text == "/")
            {
                int zbytek = (prvnic % druhyc);
                if (zbytek == 0)
                {
                    int total = (prvnic / druhyc);
                    prvnit.Text = prvnic.ToString();
                    druhyt.Text = druhyc.ToString();
                    vysledek.Text = total.ToString();
                }

            }

this will not write any number to my calculator because it has a numeric remainder.

What I could write in ELSE to generate another number, and so on until the number was completely?




Aucun commentaire:

Enregistrer un commentaire