09-23-2020 11:46 AM
Hi
I am using math.random() function of mapper component to generate unique guids. I am worried that after repetitive use of this function it will generate duplicate results. Is there any way i can be sure that it doesnt generate same guids. Is there any other efficient way of doing this. Please let me know.
Thanks
Yash
09-23-2020 11:58 AM
Use Math.randomUUID() instead.
09-23-2020 12:09 PM
sorry I am using math. Randomuuid () only. So this function you are saying will never return same guids.? Pls let me know as if it return duplicates than my solution will be ruined.
09-23-2020 12:21 PM
I see. Well, a random UUID is a 128-bit random value, so repeated values are VERY unlikely. But if you wanted to guarantee uniqueness, you could concatenate a timestamp:
Math.randomUUID() + Date.now().getTime()
09-23-2020 12:26 PM
Yes i can do that but it wont be a 128 bit guid if i add date. Anyother option u would like to propose.