Reputation: 3568
I am currently generating id's based on the adapters count. Using androrm an "object relational mapper especially for android," to organize the database. I would like to generate random numbers that never repeat's as the new id. Using random generated integers that never repeats would allow me to reference that id with another data set organized by that id. The count() method interferes with the other data set if an item is deleted. How would I generate random numbers that never repeat?
public boolean save() {
int id = FoodLog.objects(context(), FoodLog.class).all().count() + 1;
return this.save(context(), id);
}
Upvotes: 0
Views: 294
Reputation: 6104
You can't simply do that as far as i know, but if you want unique numbers all the time why don't you fetch the timestamp? like this:
long timestamp = Calendar.getInstance().getTime().getTime();
Upvotes: 2