lundi 20 mars 2017

C# char in random position

I`m facing with the problem of putting char in random position.

I have a table full of dots and I have to replace 30% of these dots with *

Size: 10x5

I used function Random.

                Random rnd = new Random();

                if (rnd.Next() % 10 > 3)
                    Console.Write(". ");

                else
                    Console.Write("* ");

Everything is in 2 loops which hold Length and Height of table (10x5).

But it only makes PROBABILITY of 30% to make * instead of .

It takes good position but every time I start a program there is different amount of *.

It should just have 16 of * (17 - if rounded) every time I start the program

How should I suppose to make 30% always instead of probability?




Aucun commentaire:

Enregistrer un commentaire