Click here to Skip to main content
16,004,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i am generating random number where i need character to be displayed before the number like S329014884..
plz help


regards
Manohar
Posted
Comments
CRDave1988 2-Feb-12 1:26am    
'S' is fix or that is also random
Rajesh Anuhya 2-Feb-12 1:50am    
And also random number should be Unique??

C#
public string RandomString(int randomNumber)
{
    return "S" + randomNumber.ToString();
}
 
Share this answer
 
C#
private void button1_Click(object sender, EventArgs e)
       {
           Random rn = new Random();
           string str="S"+rn.Next().ToString();
           MessageBox.Show(str);
       }

C#

 
Share this answer
 
If you want to generate random number you can use

Guid as

Guid randomNum= System.Guid.NewGuid();


or

Simple Random Number Generation[^]

now you can do like this

String finalNumber="S" + YourRandomNumber.toString();

Thanks
SP
 
Share this answer
 
v2

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