.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Steve Jackman
Imran Ghani
Santhakumar Munuswamy

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Random Number code

Posted By: Anup     Posted Date: December 04, 2009    Points:2   Category :ASP.Net
Hi,

I need a vb.net code that will give me random numbers, which i will save in a database column in a primary key field.

But the code should surely generate the random number.

Thanx & Regards

Anup

Responses
Author: Amit Mehra             
Posted Date: December 04, 2009     Points: 5   

HI Anup,

You can choose from 3 below ways to get the random number

1) This method uses random class of .NET Framework

Random rand = new Random();
int randomGenerateNumber = rand.Next();


2) this method also give you unique number and it uses datetime object

long number = DateTime.Now.Ticks;


3) This method will give you Guid which will be unique

string newId = Guid.NewGuid().ToString();



Thanks
Amit

Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Naresh             
Posted Date: December 16, 2009     Points: 5   

hi anup ,

random no generation code:

Public Function ticketno() As String
Dim builder As New StringBuilder("IBM-000")
builder.Append(randomno(1, 99999))
Return builder.ToString()
End Function

Private Function randomno(ByVal min As Integer, ByVal max As Integer) As Integer
Dim random As New Random()
Return random.[Next](min, max)
End Function

in Page load
textbox1.text=ticktno()

U will get the result as

IBM-00024952

Thanks
Naresh
Author: Prasanti Prusty             
Posted Date: December 17, 2009     Points: 5   

Hi,

chk the links.

http://www.dotnetspark.com/kb/1248-get-random-passward-string-using-guid-passward.aspx
http://www.dotnetspark.com/kb/1247-get-random-passward-string-using-guid--passward.aspx

Regards,
Prasanti


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend