cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate unique guids in snaplogic

yash_verma
New Contributor

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

6 REPLIES 6

ptaylor
Employee
Employee

Use Math.randomUUID() instead.

yash_verma
New Contributor

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.

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()

yash_verma
New Contributor

Yes i can do that but it wont be a 128 bit guid if i add date. Anyother option u would like to propose.