简体   繁体   中英

how do i generate random number loop with fix char code in c#?

I have tried to generate the six digit random number in which first three numbers are changing with random number and last three digit is in number which is amount and converted in to ascii to character now problem is i want to generate every time new code with three new digit and three fix digit which i had entered and also i had a for loop for grid view in which a qty textbox now if i enter 5 qty random six digit code had to generate for every qty with different 3 digit and 3 fix digit here's the code

Random rnd = new Random();
string text3 = textBox1.Text;
string text4 = "";
char[] array = text3.ToCharArray();
foreach (char c in array)
{
    int ascii = (int)c;
    //ascii = ((((ascii / 37 + 657) / 12) - 582) / 11);
    ascii += 23;
    text4 += Convert.ToChar(ascii).ToString();
}

//text4 = Encoding.ASCII.GetString(text4);


textBox2.Text = rnd.Next().ToString() + text4.ToString();


}
int i = 0;
for (i = 0; i < int.Parse(qtytxt.Text); i++)
{
int j = i + 1;

dt.Rows.Add(label5.Text, comboBox1.Text, j, ratetxt.Text, Sizetxt.Text);
}

dataGridView1.DataSource = dt;  

try this:

  Random rng = new Random();
    int number = rng.Next(100,1000);
    string text3 = textBox1.Text;
    string text4 =number+text3 ;
    string actualNumber=int.Parse(text4);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM