13,090,730 members (44,830 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi ,

I want a 5 digit unique numeric number generator in vb.net ,
Can anybody help me, please
Posted 13-Apr-12 3:01am
Updated 13-Apr-12 3:04am
phil.o90.1K
v2
Comments
VJ Reddy 14-Apr-12 6:46am

The Random.Next method can be used for this purpose. Please see Solution 4.

## 3 solutions

Rate this:
Please Sign up or sign in to vote.

## Solution 4

As for as I know, globally unique numbers cannot be generated using 5 digit numbers.
So, a list of numbers already generated is required, to check for the uniqueness of number generated. The `Next(Min, Max)` method of `Random `class explained here
Random.Next Method (Int32, Int32)[^]
can be used to generate a random number which `is equal to or more than Min and less than Max`.
The following code can be used to generate a unique 5 digit number
```Sub Main
Dim random As New Random(1)
Dim uniqueNumbers As New List(Of Integer)()
Dim randomNumber As Integer
For i As Integer = 0 To 10000
randomNumber = random.Next(10000, 100000)
If uniqueNumbers.Contains(randomNumber) Then
Console.WriteLine(randomNumber)
Else
uniqueNumbers.Add(randomNumber)
End If
Next
uniqueNumbers.Dump()
End Sub```

The above code snippet can be tested in `LINQPad `which can be downloaded from here
http://www.linqpad.net/[^]
v2
Rate this:
Please Sign up or sign in to vote.

## Solution 1

Start here[^] and then let us know if you run into a specific issue. We'll be glad to help.
Comments
raki1111 13-Apr-12 9:46am

i know it dude
Rate this:
Please Sign up or sign in to vote.

## Solution 3

Perhaps the articles here[^] could be of help.

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

Top Experts
Last 24hrsThis month
 RickZeeland 155 Graeme_Grant 130 OriginalGriff 115 ppolymorphe 75 Wonde Tadesse 60
 OriginalGriff 3,462 Graeme_Grant 1,914 ProgramFOX 1,707 Jochen Arndt 1,645 ppolymorphe 1,552

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 14 Apr 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100