Click here to Skip to main content
16,017,373 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Hi
I want to generate random value like 344298-5FCD-477C-A5AE-930596C.
when i click on button i want generate new value..


Thanks in advance,
Pawan.
Posted

If you mean a GUID, then use System.GUID.NewGuid().

If the string/value you want to generate is not a GUID, you will need to write your own logic (using the Random() class).
 
Share this answer
 
v2
C#
int patternsNum = 3;// the number of string serial want to create example 5: 44850-rt64x-xFtmt-tyuxu-cbhyt6
           int patternLength = 3; // the lenght of each pattern example 4: xtry
           string[] buff = new string[3];

           string patt = "";
           int xx = 64;
           for (int i = 0; i < patternsNum; i++)
           {
               patt = "";
               for (int j = 0; j < patternLength; j++)
               {
                   Random pat = new Random(64);
                   int inte = xx + pat.Next(32) ;
                   xx = inte+Convert.ToInt16(DateTime.Now.Second);
                   char ch = Convert.ToChar(inte);
                   patt += ch.ToString();
               }
               buff[i] = patt;
           }

           // out:
           foreach (string x in buff)
           {
               MessageBox.Show(x);
           }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900