Hi im trying to make it so I can generate a random number 1-35 so for example if the number is 25 it will write out in a string 25 equal signs. How can I do that?
Random r = new Random();
r.next(1, 35);
R's result = 25
string result = 25 equal signs
Hi im trying to make it so I can generate a random number 1-35 so for example if the number is 25 it will write out in a string 25 equal signs. How can I do that?
Random r = new Random();
r.next(1, 35);
R's result = 25
string result = 25 equal signs
Class string has a constructor that can do the work for you.
Random r = new Random();
int number = r.next(1, 35);
string result = new string('=', number);
Note also that it should be r.Next() not r.next().
Random r = new Random();
int occurrences = r.Next(1, 35);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < occurrences; i++)
{
sb.Append('=');
}
string output = sb.ToString();
Console.WriteLine(output);
You need a loop to repeat adding = to your result.
Update your code to
Random r = new Random();
int total = r.next(1, 35);
string result = "";
for (int i = 0; i < total; i++)
{
result += "=";
}