Agil Asadi Agil Asadi - 1 year ago 91
C# Question

Random number generator 8n c#

Now I always had problems with random number generating in other languages. I need to generate 1000 random numbers with 6 digits length but it must have 2 letters before the 6 digites and the letters will stay constant through all numbers. I will be copying these cods to use on some kind of products. Console application is fine at this point as well. All the numbers must be different

Answer Source

You could try this:

private void btnSubmit_Click(object sender, EventArgs e)
    //clear old data

    //The prefix of the numbers
    String letters = txtLetters.Text;
    if (string.IsNullOrEmpty(letters))
        //returns when the prefix is empty
        MessageBox.Show("Please enter a prefix!");
    //Random generator
    Random random = new Random();

    //For loop for 1000 times
    for (int i=1; i<=1000; i++)
        //add the int into the output
        int randomInt = random.Next(100000, 999999);
        txtOutput.Text += letters + randomInt + "\r";

I hope this helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download