473,796 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generate fixed length unique number

Hello.

How can I generate some fixed length unique number (for example 6 character)
based on some number like 1, 2, .. 45, 46, 47 (Generally I will use unique
ID of the database record as base number)?

Thank you.
Nov 17 '05 #1
4 2967
David Dvali <da*********@ho tmail.com> wrote:
How can I generate some fixed length unique number (for example 6 character)
based on some number like 1, 2, .. 45, 46, 47 (Generally I will use unique
ID of the database record as base number)?


What's the scope of the required uniqueness? If you're limited to 6
digits, you're not going to be able to generate more than a million of
them, for instance...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
Yes I know. I don't need more.

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
David Dvali <da*********@ho tmail.com> wrote:
How can I generate some fixed length unique number (for example 6
character)
based on some number like 1, 2, .. 45, 46, 47 (Generally I will use
unique
ID of the database record as base number)?


What's the scope of the required uniqueness? If you're limited to 6
digits, you're not going to be able to generate more than a million of
them, for instance...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Nov 17 '05 #3
David Dvali <da*********@ho tmail.com> wrote:
Yes I know. I don't need more.


Could you be a bit clearer? What's your actual situation? Why can't you
just use the unique ID of the database record as the number itself?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
I was thinking the same. Just left pad the number with zeros if for some
reason you needed a total of 6 digits for formatting or something.

--
William Stacey [MVP]

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
David Dvali <da*********@ho tmail.com> wrote:
Yes I know. I don't need more.


Could you be a bit clearer? What's your actual situation? Why can't you
just use the unique ID of the database record as the number itself?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6252
by: vishal | last post by:
i want to generate a random number of a fixed length so how can i do this ?? i know some function which returns a single random character at a time but is there any built-in function which takes length of string and return a random string of that length?????? can i implement mechanism so that the random number generated is form a list of characters i specify. e.g. suppose if i want to create a random
4
8205
by: darin dimitrov | last post by:
Hello, I need help with an algoritm that given a set of "n" distinct numbers will generate all the possible permutations of fixed length "m" of these numbers WITH repetitions (a total of n^m possibilities). For example: given the set {1, 2} would output: 111,112,121,122,211,212,221,222 if we fix m=3.
2
4552
by: Chris Dunaway | last post by:
I have a web service which is accessed by a windows forms application. When the application submits a unit of work (a "job"), I want to return a job receipt or tracking number back to the application. My requirements are these: 1. The receipt number must be unique (like a guid is unique) 2. The receipt must be NON sequential. 3. If possible, I'd like it to be 10 to 12 characters long. 4. If possible, I'd like to include only...
3
2539
by: Tran Hong Quang | last post by:
Hi, I am new to C. How to generate an fixed-length string containing an random digits? for example string of 5 characters, the value can be 03234 or 23423 or 02343 Thanks Tran Hong Quang
12
5231
by: Jim Michaels | last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or mysql. I have not been able to do either. I get the same number back several times from PHP's mt_rand() and from mysql's RAND(). any ideas? I suppose I could use the current rancom number as the seed for the next random number. but would that really work?
15
2997
by: Orchid | last post by:
Hello, I am looking to generate a unique ID field on MS. Access. The ID is with 10 digits with the combination of 5 Letters from the 26 letters and 5 Numbers from 1 to 9. The letters and numbers are picked randomly. When I click a button with the VB code on a form, it will create the ID on a table call "Customer table". Can someone help me on how to write the VB code to generate the ID?? Thanks in advance for your help!!
15
37600
by: Ashish Khandelwal | last post by:
As MSDN is not giving us guarantee upon uniqueness of Hash Code, so could any one suggest me that how to generate a unique Hash Code for same string always, and generate different-2 Hash Code Different-2 string.
6
13503
by: =?Utf-8?B?VGFydW4=?= | last post by:
Hi, I have to generate a fixed length text file.I have a file formats like fields details as well as its length and position.what actually i have to do that i will get the data from the databas and then i need to create a fixed length flat file as per format.so please give me a sample for this.
0
9535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10467
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10244
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10201
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.