asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search








Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Code Samples
Components
Tools
New
Free
Downloads
Vendors
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Function designed to generate a extremely random alphanumeric key Number of possible different combinations with defined array and digits set to 13, is 36 to 13 power which is 170,581,728,179,578,208,256 unique combinations, this should be adequate for most applications. Writen by Frederick S. Kania E-Mail: fkania@mich.com

This script is very easy to modify to your needs, I needed this for a certificate generation system which needed a very unique code which I could use to pass to a SQL DB. I am currently using this function and setting the returned value as a unique key in the DB. I am also checking the DB to verify the number does not exist to make sure I do not get any errors/duplicates.

I don't know that anyone would need any more than this amount of combinations, but you could increase the array to be case sensitive, which would raise your randomness to array size raised to the amount of digits required.

Define gen_key function where digits is the number of digits needed in your random string


<%
Function gen_key(digits)

'Create and define array
	dim char_array(50)
		char_array(0) 	=	"0"
		char_array(1)	=	"1"
		char_array(2)	=	"2"
		char_array(3)	=	"3"
		char_array(4)	=	"4"
		char_array(5)	=	"5"
		char_array(6)	=	"6"
		char_array(7)	=	"7"
		char_array(8)	=	"8"
		char_array(9)	=	"9"
		char_array(10)	=	"A"
		char_array(11)	=	"B"
		char_array(12)	=	"C"
		char_array(13)	=	"D"
		char_array(14)	=	"E"
		char_array(15)	=	"F"
		char_array(16)	=	"G"
		char_array(17)	=	"H"
		char_array(18)	=	"I"
		char_array(19)	=	"J"
		char_array(20)	=	"K"
		char_array(21)	=	"L"
		char_array(22)	=	"M"
		char_array(23)	=	"N"
		char_array(24)	=	"O"
		char_array(25)	=	"P"
		char_array(26)	=	"Q"
		char_array(27)	=	"R"
		char_array(28)	=	"S"
		char_array(29)	=	"T"
		char_array(30)	=	"U"
		char_array(31)	=	"V"
		char_array(32)	=	"W"
		char_array(33)	=	"X"
		char_array(34)	=	"Y"
		char_array(35)	=	"Z"

'Initiate randomize method for default seeding
	randomize

'Loop through and create the output based on the the variable passed to
'the function for the length of the key.
	do while len(output) < digits
		num = char_array(Int((35 - 0 + 1) * Rnd + 0))
		output = output + num
	loop

'Set return
	gen_key	=	output
End Function

'Write the results to the browser, currently setting a 13 digit key
response.write "<pre>" & gen_key(13) & "</pre>" & vbcrlf
%>





email this code sample to a colleague


Support the Active Server Industry



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM eBook: Planning a Service Oriented Architecture
IBM eBook: Choosing the Right Architecture--What It Means for You and Your Business
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Avaya Article: Using Intelligent Presence to Create Smarter Business Applications
Intel Go Parallel Article: Getting Started with TBB on Windows
Microsoft Article: 7.0, Microsoft's Lucky Version?
Avaya Article: How to Feed Data into the Avaya Event Processor
IBM Article: Developing a Software Policy for Your Organization
Microsoft Article: Managing Virtual Machines with Microsoft System Center
Intel Go Parallel Article: Intel Threading Tools and OpenMP
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Silverlight 2 App and Walkthrough: Leverage Silverlight 2 with SQL Server and XML
IBM Article: Enterprise Search--Do You Know What's Out There?
HP Demo: StorageWorks EVA4400
Microsoft Article: The Progress and Promise of Deep Zoom
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES