Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

random entry generating.

Status
Not open for further replies.

tar565

Programmer
Jan 24, 2005
39
IE
I am writing into a db and have to create a unique random value for each entry. The value can be made up of any number of digits, chars or letters.

Any help would be great.
 
Can you give us more information, is it a web application, are you using session variables, are you running this on *nix, Windows etc etc

Depending on your situation, there are a number of variables you can use to create faceted codes,(time, process id, session key(random)) which could then be passed to a function to create a totally random id.

What's your need for randomness?

--paul

cigless ...
 
I am running this on windows. I am writing into a MYSQL db. I have not designed the db and cannot change it.

Basically I am writing a line into a table called emails and I need to generate a unique id for each line consisting of chars, digits and letters.


 
What's the need for randomness, an autoincremental index would sort this out for you?
--Paul

cigless ...
 
Sounds like you need a GUID. Or a UUID. Googling 'perl guid' turns up module Data::UUID which generates 128-bit UUIDs in a number of formats. This will give you a string that looks similar to
Code:
4162F712-1DD2-11B2-B17E-C09EFE1DC403
Haven't tried it, but most other systems (.NET, Java) use them so they should be OK for your purposes.

Allegedly they are guaranteed to be unique until the year 3400, by which time you will probably have rolled off the project...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top