C#: Add a random word or letter to text?

Status
Not open for further replies.

kytro360

Member
Original poster
member
Joined
Sep 9, 2009
Posts
376
Reaction score
6
Points
75
Hi, basically I want to know how to add a random letter or number to the end of a text. I want it to be random.

Basically I am making a webrequest to register on a site and want to add random characters to text that I imported from a file into a textbox so when my bots registering it'll just add a random word or number at the end of the text.

Any help would be appreciated :)
 

Flip

Old School
old school
member
Joined
Jul 23, 2009
Posts
263
Reaction score
69
Points
108
There are a bunch of ways to do this, but here's one.

Code:
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private const string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Random rand = new Random();
            string name = "John";
            name += alphabet[rand.Next(0, 25)];
            richTextBox1.AppendText(name + "\n");
        }
    }
}

nh6YR.png


If you want different letters or numbers you can simply change the string, just remember to change the random range [ex: you want to add 0 through 9 so it changes to (0, 35)]

If you want more characters just put it in a for loop.
 
  • Like
Reactions: kytro360
Status
Not open for further replies.