473,554 Members | 4,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generate random string

Hi all,

I need to be able to create some license keys for an application. Ideally
these wouldn't be too long in length (ie, easier to remember/type in), but I
would like them to be auto generated and a check made to see whether or not
that key has already been used, something which could generate up to about
10000 keys (or more if the string doesnt have to be too long) would be very
useful.

A combination of letters, numbers, upper and lower case is needed.

I could sit here and start plugging away at this, an array for numbers, an
array for letters, a random test for uppercase/lowercase etc, but it occured
to me that I'm probably just reinventing the wheel a bit here, someone must
have done this before!

Has anyone produced anything similar to this in the past?

Any help would be appreciated.

Regards

Rob
Jul 19 '05 #1
18 9762
Why not just use a GUID?

--
http://www.aspfaq.com/
(Reverse address to reply.)


"Rob Meade" <ro********@N O-SPAM.kingswoodw eb.net> wrote in message
news:9n******** ************@ne ws-text.cableinet. net...
Hi all,

I need to be able to create some license keys for an application. Ideally
these wouldn't be too long in length (ie, easier to remember/type in), but I would like them to be auto generated and a check made to see whether or not that key has already been used, something which could generate up to about
10000 keys (or more if the string doesnt have to be too long) would be very useful.

A combination of letters, numbers, upper and lower case is needed.

I could sit here and start plugging away at this, an array for numbers, an
array for letters, a random test for uppercase/lowercase etc, but it occured to me that I'm probably just reinventing the wheel a bit here, someone must have done this before!

Has anyone produced anything similar to this in the past?

Any help would be appreciated.

Regards

Rob

Jul 19 '05 #2
Rob Meade wrote:

I need to be able to create some license keys for an application.
Ideally these wouldn't be too long in length (ie, easier to
remember/type in), but I would like them to be auto generated and a
check made to see whether or not that key has already been used,
something which could generate up to about 10000 keys (or more if the
string doesnt have to be too long) would be very useful.

A combination of letters, numbers, upper and lower case is needed.

I could sit here and start plugging away at this, an array for
numbers, an array for letters, a random test for uppercase/lowercase
etc, but it occured to me that I'm probably just reinventing the
wheel a bit here, someone must have done this before!

Has anyone produced anything similar to this in the past?


This will do far more than 10,000, and will give you uniqueness:

GUID = Server.CreateOb ject("Scriptlet .Typelib").GUID


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 19 '05 #3
Thanks chaps, but how will it know its 'unique'? ie, how will it remember
that it hasnt already used that one? I'll try the code in a minute or two -
but if you happen to reply prior to that - how many characters does this
generate by the way?

Thanks again,

Rob
Jul 19 '05 #4
Ok - so I got this:
Jul 19 '05 #5
(I hate ctrl+enter!!).. .

I got this...

FFDA9960-8C53-497F-9D8F-A736352F21C0

That and a password is what a user will need to enter when logging into a
members area to download any updates to an application - bit long - hard to
remember etc...(great for uniqueness mind!)...

Thoughts/suggestions...

Rob
Jul 19 '05 #6
Well, GUID stands for Globally Unique IDentifier, so you can do the math
from there...

Keep this in mind, of course, if you are going to generate or response.write
from ASP:
http://www.aspfaq.com/2358

--
http://www.aspfaq.com/
(Reverse address to reply.)


"Rob Meade" <ro********@N O-SPAM.kingswoodw eb.net> wrote in message
news:u7******** ********@news-text.cableinet. net...
Thanks chaps, but how will it know its 'unique'? ie, how will it remember
that it hasnt already used that one? I'll try the code in a minute or two - but if you happen to reply prior to that - how many characters does this
generate by the way?

Thanks again,

Rob

Jul 19 '05 #7
Why does a serial # have to be easy to remember? Do you remember your
Windows product key, your Photoshop serial number, hell your credit card
number?

If you want something easy to remember, then toss this random string
generation out the window, and make users choose their own password!

--
http://www.aspfaq.com/
(Reverse address to reply.)


"Rob Meade" <ro********@N O-SPAM.kingswoodw eb.net> wrote in message
news:S9******** ********@news-text.cableinet. net...
(I hate ctrl+enter!!).. .

I got this...

FFDA9960-8C53-497F-9D8F-A736352F21C0

That and a password is what a user will need to enter when logging into a
members area to download any updates to an application - bit long - hard to remember etc...(great for uniqueness mind!)...

Thoughts/suggestions...

Rob

Jul 19 '05 #8
"Aaron [SQL Server MVP]" wrote ...
Why does a serial # have to be easy to remember?
Because they'll be using it often for logging in purposes, hence in my first
post suggesting that it didnt have too many characters.
Do you remember your Windows product key, your Photoshop serial number,
Absolutely not - agree fully with you there, but I dont need to enter those
every time I want to download a patch/fix etc..
hell your credit card number?
That one I do know - but my card kinda glows red so its easy to see :o)
If you want something easy to remember, then toss this random string
generation out the window, and make users choose their own password!


They'll have a password as well as the key Aaron, the licence number I guess
is affectively their username.

Regards

Rob
Jul 19 '05 #9
"Aaron [SQL Server MVP]" wrote ...
Well, GUID stands for Globally Unique IDentifier, so you can do the math
from there...
Whilst not really wanting to go down this road, but feeling propelled to say
it....there must be an upper limit to the number of combinations though
surely - if I do the response.write GUID for example and then held F5 down
on my PC lets say for the rest of my life time I'm surely going to get a
duplicate eventually???

I'm unaware (and you might have to excuse my ignorance a little as Maths was
never a strong subject for me) - of anything thats simply endless - apart
from space - but even that must have boundaries somewhere...(wo oow - brain
is starting to melt a bit now)..
Keep this in mind, of course, if you are going to generate or response.write from ASP:
http://www.aspfaq.com/2358


Thanks for that, I didnt even know about the GUID ability in ASP so I've
learnt something new tonight :o)

Rob
Jul 19 '05 #10

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

Similar topics

3
6232
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...
2
8277
by: Laphan | last post by:
Hi All This is a strange request, but I just cannot fathom how to do it. In theory the requirement is very basic, but in practise its a noodle!! I have 10 team names like so: Team A Team B
2
18010
by: Henry | last post by:
Hi, How can I generate an eight digit random? Can I use the staff name to generate it? May I ask is there any sample c# code to see? Thanks
11
15443
by: Zeya | last post by:
I need to randomly generate a 16 digit hex number in C# code. How can I do this? Thanks.
10
2600
by: Crirus | last post by:
Is there a function that return some random ID like string alphanumeric? Like this: A35sDsd1dSGsH Thanks Crirus
6
3063
by: comp.lang.php | last post by:
/** * Generate the random security image * * @access public * @param $willUseFilePath (default false) boolean to determine if you will be using a file path * @param mixed $filePath (optional) file path to store image resource object contents * @see actual_path */
12
5202
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?
20
7822
by: jjmillertime | last post by:
I'm new so i apologize if this is in the wrong spot. I'm also new to programming in C and i've been searching for quite a while on how to create a program using C that will generate two random numbers, multiply them, and ask you for the result. It also needs to have four responses for both right and wrong answers and should print them...
8
7194
by: Marc | last post by:
Hi all, I have to generate and send to a printer many 6 digit alphanumeric strings. they have to be unique but I cannot check in a database or something like that if it have already been printed. the string has also to seem a random one and it cannot have an apparence of a sequence. My first approach is to do it with a decimal counter and...
0
7503
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...
0
7781
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. ...
0
8017
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...
1
7538
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...
1
5421
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3543
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3531
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2003
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
817
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...

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.