i want to generate unique id in c. what should i do? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

i want to generate unique id in c. what should i do?

.

8th May 2020, 6:57 PM
Saurabh
Saurabh - avatar
3 Answers
+ 1
you could generate a random string , then use a hashmap to cache the result. if you generate a string already in cache you throw away the result & regenerate to make sure its unique. If it is unique? Store it in cache and return it. advantage is hashmap lookup time is 0(1) best case , so its as fast as accessing array element.
9th May 2020, 1:14 PM
Gen2oo
Gen2oo - avatar
+ 1
can i ask. what is id, a unique string or unique number??
8th May 2020, 7:15 PM
Gen2oo
Gen2oo - avatar
0
string
9th May 2020, 12:57 AM
Saurabh
Saurabh - avatar