NSFileManager unique file names

Create your own file name: CFUUIDRef uuid = CFUUIDCreate(NULL); CFStringRef uuidString = CFUUIDCreateString(NULL, uuid); CFRelease(uuid); NSString *uniqueFileName = [NSString stringWithFormat:@”%@%@”, prefixString, (NSString *)uuidString]; CFRelease(uuidString); A simpler alternative proposed by @darrinm in the comments: NSString *prefixString = @”MyFilename”; NSString *guid = [[NSProcessInfo processInfo] globallyUniqueString] ; NSString *uniqueFileName = [NSString stringWithFormat:@”%@_%@”, prefixString, guid]; NSLog(@”uniqueFileName: ‘%@'”, uniqueFileName); NSLog …

Read more

How to generate unique 64 bits integers from Python?

just mask the 128bit int >>> import uuid >>> uuid.uuid4().int & (1<<64)-1 9518405196747027403L >>> uuid.uuid4().int & (1<<64)-1 12558137269921983654L These are more or less random, so you have a tiny chance of a collision Perhaps the first 64 bits of uuid1 is safer to use >>> uuid.uuid1().int>>64 9392468011745350111L >>> uuid.uuid1().int>>64 9407757923520418271L >>> uuid.uuid1().int>>64 9418928317413528031L These are …

Read more

Short unique id in php

Make a small function that returns random letters for a given length: <?php function generate_random_letters($length) { $random = ”; for ($i = 0; $i < $length; $i++) { $random .= chr(rand(ord(‘a’), ord(‘z’))); } return $random; } Then you’ll want to call that until it’s unique, in pseudo-code depending on where you’d store that information: do …

Read more