Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a unique identifier?

Tags:

I need to generate some int value that would never repeat (at least theoretically). I know there is arc4random() fnc but I'm not sure how to use it with some current date or smth :(

like image 649
Centurion Avatar asked Aug 10 '11 19:08

Centurion


People also ask

How do I create a unique identifier in Excel?

1. type 1 into the cell which is adjacent to the first data you want to add ID number. 2. Then in the cell below it, type this formula =IF(B1=B2,A1,A1+1), press Enter key to get the first result, drag fill handle down until last data showing up.

What is an example of a unique identifier?

Some agencies give people a 'unique identifier' instead of using their name. Examples are a driver's licence number, a passport number, a student ID number, or an IRD number.

How is a GUID generated?

A GUID (globally unique identifier) is a 128-bit text string that represents an identification (ID). Organizations generate GUIDs when a unique reference number is needed to identify information on a computer or network. A GUID can be used to ID hardware, software, accounts, documents and other items.

Can Google Forms generate a unique ID?

Google Forms automatically assigns a unique, non-sequential and non-guessable identifier (id) to every form entry. This Unique Id contains a mix of alphabets and digits. You can use this unique ID in subject line and message body of your email template with the help of dynamic form fields.


2 Answers

This returns a unique key very similar to UUID generated in MySQL.

+ (NSString *)uuid {     CFUUIDRef uuidRef = CFUUIDCreate(NULL);     CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);     CFRelease(uuidRef);     return [(NSString *)uuidStringRef autorelease]; } 

ARC version:

+ (NSString *)uuid {     CFUUIDRef uuidRef = CFUUIDCreate(NULL);     CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);     CFRelease(uuidRef);     return (__bridge_transfer NSString *)uuidStringRef; } 
like image 185
Nandakumar R Avatar answered Sep 27 '22 20:09

Nandakumar R


A simple version to generate UUID (iOS 6 or later).

Objective-C:

NSString *UUID = [[NSUUID UUID] UUIDString]; 

Swift 3+:

let uuid = UUID().uuidString 

It will generate something like 68753A44-4D6F-1226-9C60-0050E4C00067, which is unique every time you call this function, even across multiple devices and locations.

Reference: https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSUUID_Class/Reference/Reference.html

like image 26
MaikonFarias Avatar answered Sep 27 '22 20:09

MaikonFarias