NetTalk Central
NetTalk Web Server => Web Server - Share Knowledge => Topic started by: Niels Larsen on March 28, 2014, 12:08:25 AM
-
Hi
I use GUIDs in many of my programs.
Maybe someone could benefit from it.
I do it like this:
Inside Global Map:
MODULE('winapi')
CoCreateGuid(*?),UNSIGNED,PASCAL,RAW,DLL(1),NAME('CoCreateGuid')
StringFromGUID2(*?,*?,LONG cchMax),UNSIGNED,PASCAL,RAW,NAME('StringFromGUID2')
WideCharToMultiByte(UNSIGNED CodePage=0,USHORT dwFlags=0,*? lpWideCharStr,LONG cchWideChar,*? lpMultiByteStr,LONG cbMultiByte,? lpDefaultChar,BYTE lpUsedDefaultChar),UNSIGNED,PASCAL,RAW,NAME('WideCharToMultiByte')
END
GUID PROCEDURE(), STRING
pGuid STRING(16)
buf STRING(128)
buf2 STRING(64)
cbSize LONG
CODE
IF CoCreateGuid(pGUID)
RETURN(''
ELSE
IF StringFromGuid2(pGuid,buf,SIZE(buf)/2)
cbSize = WideCharToMultiByte(, , buf, -1, buf2, SIZE(buf2), 0,0)
IF cbSize > 0
buf2 = buf2[1 : cbSize]
RETURN(CLIP(buf2))
END
ELSE
RETURN('')
END
END
/Niels
-
Cool.
I just use the StringTheory Random function.
file:id = str.Random(16,st:Upper+st:Number)
cheers
Bruce
-
You'r right, but if you merge to databases there is a very,very small chance to get a conflict.
Yes, I know - it is very theoretical ;-)
-
Hi Niels,
>> there is a very,very small chance to get a conflict.
That's like saying that there's a small chance an alien will land on top of my building in the next minute, and whisk me away to an alternate dimension. Of course there's a chance, but it's not something I use when making any kind of decisions.
a 16 char string, with a 36 char alphabet (as described below) allows for
36 ^ 16 combinations. that's
7 958 661 109 946 400 884 391 936
that means that if you had a single table with a billion records, for every single human on this planet, you would be able to merge all their data and still not get a conflict.
Unfortunately most of us are really bad at math with big numbers, but the risk of you, and your wife
being struck by lightning at the same time
every day
at exactly the same time of day
for 1000 years
is more likely.
sure there's a _chance_, but it's not gonna happen.
Let me put it another way. Given the mean time between failure of disk storage, what should worry you is a random bit switch in your data casing a 747 to fall out of the sky. By comparison that's so likely it's basically guaranteed to happen.
cheers
Bruce
-
In comunication with other entities you could be forced to use GUID's of a special version of the algorithm creating a UUID. I also use the API Niels showed here because of security reasons (external demand for version 4 GUID's).
Ciao, Thomas
BTW: "128-bits is big enough and the generation algorithm is unique enough that if 1,000,000,000 GUIDs per second were generated for 1 year the probability of a duplicate would be only 50%. Or if every human on Earth generated 600,000,000 GUIDs there would only be a 50% probability of a duplicate."
-
Just like the lottery. There's a 50% chance of winning - either you win or you don't.
-
LOL - That's brilliant - I must remember it!