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

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

need help to generate unique random numbers

Posted By:      Posted Date: September 27, 2010    Points: 0   Category :ASP.Net

I want to generate a unique random number everytime a user submits a form. As the form is submited the data of the form should be placed in a database and a unique random number should be generated so that the user can later use this unique random number to reterieve his details from the database that refer to his unique random id. The unique random number should be atleast 9 digits long. Please help me on this.

View Complete Post

More Related Resource Links

Generate Random Numbers

SQL Server has a built-in function that generates a random number, the RAND() mathematical function. The RAND math function returns a random float value from 0 through 1.

how to generate a unique random number on a form submission?


I want to generate a unique random number everytime a user submits a form. As the form is submited the data of the form should be placed in a database and a unique random number should be generated so that the user can later use this unique random number to reterieve his details from the database that refer to his unique random id. The unique random number should be atleast 9 digits long. Please help me on this.

Update with unique random generated values.

Hi there, I have an issue with an update of a column with unique random generated values, using SQL 2005. What I want to achieve is to create unique username for a list of let's say 1000 rows. My approach, which may be wrong, is as follows: to create a view to retrieve a random generated number of 7 digits; to use a function that retrieves the number from the view and checks if it is unique in the table or not (if it is, the number is returned, if it is not, a new one will be generated and so on); to update the table using that random generated number. The problem is that it does not work. It does not generate unique numbers, not all the times (you have to test by running the code few times). I suspect it is something with the update, but not sure how to solve it. Here are the steps to reproduce the problem. Create the table: CREATE TABLE [dbo].[TB_Temp]( [ID] [int] IDENTITY(1,1) NOT NULL, [ADM_USERNAME] [nvarchar](7) COLLATE Latin1_General_CI_AS NULL, ) ON [PRIMARY] Add some test rows: DECLARE @i INT SET @i = 0 WHILE @i <= 1000 BEGIN INSERT INTO TB_TEMP (ADM_USERNAME) VALUES ('') SET @i = @i +1 END Create the view to random generate 7 digits numbers: CREATE VIEW vw_RandNumberForAdminUserName AS SELECT ROUND((9999999 - 1000000 - 1) * RAND() + 1000000, 0) AS RandNumber Create the function to retrieve the unique 7 digits number: CREATE FUNCTION [dbo].[fn

Generate Unique Id

I want a list column that will generate a unique id everytime a new item is added to the list. The item will have a predefined prefix and then add a number. All the ones I have tried from other sites have failed. 

how to use random generate number with linq

how to use random generate number with linqthanks in Advance:)

Submitting Infopath forms to a Sharepoint Library - how can I generate a unique name for each record


I have published an Infopath form to a Sharepoint Library. What is the best way to ensure the following:

1. have a name per saved form (I do have a name field which has a set certain amount of available names in it which I am currently using as the form name - coming from an XML file)
2. users can edit already submitted forms without changing the name of the saved form
3. Ensure that users who may create a new form which happens to have more or less the same data as a previously saved form don't end up overwriting the existing one and hence I end up loosing saved data?

Using the name field + allow overwrite will allow me to have a unique name for the form and allow it to be overwritten but if I create a new form with the same name and maybe just a few small differences I will overwrite the existing form which is what I don't want - someone may not realise that an existing form with the relevant information already exists and we could loose already saved information

Any advice would be greatly appreciated.


generate a unique code


Hiii Friends,

I have to generate a unique customer code like this-

'cbd'+first letter of customer name+incrementer


cbd is hard coded means reamain fixed in each customer code

first letter of cust_name is like Bell Companies- B


incrementer must be four digit number like 0001,0002,0888 etc.

Here incrementer should start with 0001 for each customer means

for EX-

BELL COMPANIES - CBDB0001 then it should increment for customers having name started with B

TEL POWERS- CBDT0001 then it should increment for customers having name started with T

hopefully all of u understand what i mean

plz rep asap

any help will be greatly appreciated

thanx and regards 

Create an Infopath form to generate unique number MOSS 2007


I created an infopath form that would auto generate a number to each form from following instructions at the following site.




I am wondering if it is possible to change the starting point of the ID field within sharepoint.  It starts at 1.  I would like it to start at 1000. and add 1 number each time a new infopath form is added. Or would I add a different field to accomplish this.

I am trying to populate an array with 9 random numbers but having some problems.


The first problem I am having is that it populates every cell with the same random number.  How do I get it to create a new random number?  The second problem is that I need to make sure each entry in the array is unique.

Here's my code.  Does anyone see the problem?  

Dim UsedCards(5) As Integer
   Dim intRandomNumber As Integer
   Dim X As Integer
   Sub Page_Load()
   End Sub
   Sub DealCards()
    UsedCards(0) = GetRandomNumber(1, 52)
    UsedCards(1) = GetRandomNumber(1, 52)
    UsedCards(2) = GetRandomNumber(1, 52)
    UsedCards(3) = GetRandomNumber(1, 52)
    UsedCards(4) = GetRandomNumber(1, 52)
   End Sub   
   Function GetRandomNumber(ByVal intLowLimit As Integer, ByVal intHighLimit As Integer)
    Dim RandomGenerator As Random

How to generate a random number sequence that is non-repeating in visual basic .net ?


I am writing a matching program, and need 24 objects to randomly appear, each twice, across 48 spaces. I figured the best way for me to do this would be to assign the positions a number 1 through 48. but the problem is I can't find a way to generate a random number sequence in visual basic 9 .net

I found many examples in visual basic .net but the conversion doesn't work. If not some code, many some example programs that either use a random number sequence or randomly sets the position of objects.


Generate thumbnails on the fly

There are many posts how to generate thumbnails using ASP.NET. Some good some less. Be sure to get distance from the versions that use Image.GetThumbnailImage method.

Unique content within master page based on conditions met


 Hi all-

I would like to present users with unique content based on certain conditions being met as they land on the home page (default.aspx).  The condition logic will be in the VB code behind Page Load event. The content will go in a content placeholder as specificed from the master page. 

However, the content change wouldn't be something small (ie making a panel or label visible or not) but rather it will be different HTML,  Divs and databound gridview content.  The HTML content will be stored in the database.

Can someone point me in the right direction for best practices on how to accomplish this?


Unique ID throughout entire request



I am hoping somene here could advise me on a better solution to my present problem.  First a little background information on the application. 

I have a web application using the 3.5 framework.  The structure of this application is as follows: UI -> WebService   -> Business Layer -> DataAccess Layer.   What I want to accomplish is for every request (click on a link or button) have a unique identifer that follows this request through its entire lifecycle.  This unique identifer can be accessible anywhere within this request.  We use Response.Redirects which could easily be changed to Server.Transfers (although I do not want to do that) but  the problem lies with the web service calls.  Currently, a GUID is set in the ApplicationRequest.  This GUID checks for a guid value in the RawURL and if so, assigns this value to a HttpContext Item.  If not, HttpContext.Items gets a new one created.  However, this idea is wrong and will need to be revisisted.  The bigger problem is with the web service calls.  Without changing every web service method signature, and every call for that matter, is there a way of getting this GUID there.  I created a web method in every web service so that each time I instantiate a web service object in the UI, before calling any

Unique text value in databse column


Hi Everyone!

I know this is probably a very basic question but how do I keep a column's text values unique in SQL server (ie for a unique username)?  The column is not an integer it's varchar(50), and it's not the primary key but I could make it the primary key if recommended.

The front end could handle it;  where the user would enter text, it's validated, then a query is done to see if that username is available.  If so, then user can decide to choose it and an insert is done, if not they pick a new username and process repeats.  With this approach, the responsibility of keeping the value unique solely rests on the front end, nothing on the database side.

Is this the correct way to handle this? 

Thank you!


Generate rss feed with HTTPHandler





I'm looking for link/tutorials/code samples on How to create HttpHandler for generating rss feeds for a website.




ASP.NET Designer - How Do I generate this Design-Time Markup?


I want to generate this:
    <x:MyControl id="a" runat="server">
            <x:MyScript .. />

How to generate large pdf's?


Hi all,

I am using rdlc reports in my appln. Am trying to generate a huge pdf file which almost consists of 1500 - 2000 pages.
I have used ReportViewer and am adding datasource (Generic collection) to report. But am getting system out of Memory exception as it is a huge file.
Can any one suggest me how to generate large pdf files in asp.net c#

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

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