Create unique Number for email - iphone

I have an IOS app that takes a photo of a hazard, and sends the photo, along with some additional information, in an email. i want to generate a unique number for the email. this must be a unique number no matter how many users there are who have downloaded the app (ie - i cant just use a random number generator because it is possible someone else could generate the same random number.)
Any suggestions, tutorials, comments would be greatly appreciated.

As far as I understood from your question, you need a key which is globally unique. Then, using an integer will not be a good solution. You need to use string.
I suggest using the following code for creating one...
NSString * uniqueKey = [[NSProcessInfo processInfo] globallyUniqueString];
I hope it helps...

Related

How do I generate a unique id from an auto incremented integer?

I have an auto incremented id (an int) that I want to convert in to something less "mine-able". Basically I don't want people to be able to access data/0, data/1, data/2, etc. and rip through our entire database. I was thinking of just hashing the ID but I wasn't sure if I could guarantee uniqueness.
Let's say the value range is from 1 to a couple hundred million. It may be that one of the hash algorithms can guarantee uniqueness within those parameters.
If not, what would be a good approach to take?
I did consider hashing and then appending the ID.
I'm trying to avoid using a GUID because it would require a lot of changes to existing code so I'd prefer to transform the data I have.
EDIT:
To further explain the situation - these are static resources that are being hit. I don't have to go to a database and reverse it or look it up against something else. Imagine a listing of products - a user might have a link to a specific page but I don't want them to be able to programatically go through every page so I need an non incrementing ID.
As far as I know hashing is intended to create unique ID based on some concrete data (e.g. name, surname etc.). Hashing auto incremented ID wont help you much. If someone searches through your database by entering an auto incremented ID, that ID will be passed to hash function as parameter and he will still get the data he wants. So I think that better solution would be to hash some other data in order to get a unique ID. If you do so then a person who searches through you database would have to know exact data that is stored in there (e.g. He would have to know exact name of you employee, or his SSN).
Hope that helps!
Use something pseudo-random to salt the value before hashing if there is no need for reverse lookup.

Algorithm to generate a user unique, 6-character confirmation code?

I'd like to be able to create an algorithm that generates a 6 character confirmation code (e.g. A1JU2Z) that will be unique for a given (user, code) pair. The reason is, I'd like to keep the code at 6 characters, but using a trimmed set of alphanumerics (to avoid confusion with 1 and I, etc) only allows for ~300 million codes before collisions occur. Sure I may never need 300 million codes, but if I do, it will be a huge pain to go back and fix this.
So is there a way to utilize the user ... say their username, to generic unique codes such that if the same user wants to generate another code, its guaranteed that it is unique for them? (This is of course assuming a single user doesn't generate over 300 mill codes)
Thanks!
If the ID is unique only to the current user, you can just generate each character of the ID randomly. As long as the user is not expected to generate a large number of such IDs, you will have reasonable chance of not generating the same ID more than once (you need to do some math to get exact numbers for the expected chance of collision as the number of generated ID grow).
If you must not have collision at all cost, you need to either keep all previously generated IDs and do a comparison for the new one, or keep the count of the generated IDs (this requires a scheme where the ID generation is deterministic based on the count, but also unique -- a very simple case would be {ID=count; ++count;})
I think you can use a simple password generator like this : http://www.webtoolkit.info/php-random-password-generator.html
in combination with a check algorithm to be sure it is not already used.
$pass=generate_password();
$found=find_password($pass);
while($found){
$pass=generate_password();
$found=find_password($pass);
}
save_password($user,$code,$pass);
generate_password() is the function refered in the link.
find_password() is a function you have to write to check already generated codes in a database.
save_password() is a function you have to write to store the generated code in a database.
The code is in PHP, but the logic is here.
The password generator in the link is easy to understand, you can get 6 chars long, with the character rules you want.

Facebook File Names

I've been checking out Facebook code lately and all of their images and files have names comprised of just random letters and numbers like "FSEB6oLTK3I.png", "cWd6w4ZgtPx.png", "GsNJNwuI-UM.gif". What do these names mean? Are they using some sort of naming system (if so, what is it?) or are the names just random?
They are generated completely randomly. And probably done for good reasons too. If this name was predicable then you could see someone's random upload by just knowing their name or id.
After generating a file name, they store the image on disk and store the image name in the database. Again this purely done for security reasons.
I think the names are generated completely random. If that's not the case, one would need a lot more data regarding the images/files and their uploaders, not to mention additional data about... well, anything that might be relevant for an upload.
I think that it is just random. They probably have a database that has all the random filenames

What is the best way to manage number with currency?

In my application it's possible to store a price for every object and the user can also choose its preferred currency.
What is the best way to store and manage number with currency in iPhone SDK?
More infos about my app:
It uses Core Data.
Number that can be stored must be of type xxx.xx (e.g. 100.00).
How can I sort these numbers ascending or descending?
What kind of attribute I must set in my entity to store a number like this?
Have you got links, docs, source or guides to show me examples? I never user number with currency, then I've got some problems with them :)
Thanks a lot,
Matthew
Store it in GP (gold pieces) with a conversion factor ;)
It doesn't look like there's a datatype for currency, so storing the number and decimal part, and a setting for the current currency, is probably as good as you're going to get. See this: HowTo for newbie: Managing currency in iPhone app

Ordering a list randomly

I have a list of 55 (or any number but 55 at the moment) questions in my iPhone app.
I have written it at the moment so it goes through the questions from 1 to 55 in number order.
However, I would like to make this order random (or pseudo-random anyway).
I can do it programatically by generating a random number to pick one of the questions and then creating a second list of numbers and checking each time that I haven't already got it before putting that question in the list and picking a new random question.
I would like to know if there is a better/easier way of doing this though?
Like it's possible to sort lists by numerical or alphabetical order using functions, is it possible to sort them randomly and what type of list should I use?
Any help is appreciated.
Thanks
Oliver
Fisher–Yates shuffle
Use a NSMutableArray, send it a sortUsingSelector: message. In the selector, return NSOrderedAscending and NSOrderedDescending randomly.