Let's say I have a code for a windows form, that generates greetings when you press a button.
string[] Greetings = new string[] { "Hi", "Hello", "Howdy!", "Hey" };
string[] Smilies = new string[] {";)", ":)", "=)", ":-)" };
Random rand = new Random();
string Greet = Greetings[rand.Next(0, Greetings.Length)];
string Smile = Smilies[rand.Next(0, Smilies.Length)];
TextBox.Text = Greet + " " + Smile;
Clipboard.SetText(TextBox.Text);
What if I want to add smilies with a probability of X%. So that they do not appear all the time, but with a chance I set in the code? What is a good way to do it?
I thought of something like this --
public void chance (string source, int probability)
{
Random chanceStorage = new Random();
if (probability >= chanceStorage.Next(0, 100))
TextBox.Text = source;
}
And then
TextBox.Text = Greet;
chance("_" + Smile, X);
Is that optimal?