How to make a GUID?

246 views
Skip to first unread message

Peter Hollebeek

unread,
Aug 11, 2011, 8:44:38 AM8/11/11
to MapInfo-L
Hi,

Lost my note from the last MapBasic course, how to make a GUID in
mapbasic?

Thanks

Peter

Bill Thoen

unread,
Aug 11, 2011, 11:46:50 AM8/11/11
to mapi...@googlegroups.com
That was 90% of the course... tsk tsk ;-)

But what you want is the Dialog statement. For the controls, they all start with Control. The oth er key resource is the online help. Here's a mini dialog example:

include "mapbasic.def"

declare sub main
sub main
dim choice as smallint

dialog title "Reload Memories"
control statictext
    title "Easily fogotten things:"
    position 12,8

control popupmenu
    position 12,20

    title "How to compute triple integrals;" +
        "Rocket Surgery - bypass plasma conduits;" +
        "Wedding anniversery;MapBasic course notes"
    value 1 into choice
    control OKbutton
        position 4,40
    control CancelButton
        position 46, 40
end sub

Uffe Kousgaard

unread,
Aug 11, 2011, 11:53:23 AM8/11/11
to mapi...@googlegroups.com
GUI - GUID. Not quite the same. In fact 25% of the word :-)

--
Regards
Uffe Kousgaard

Open position at RouteWare:
http://www.routeware.dk/download/gis_developer_2011.pdf

Bill Thoen wrote:
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

Bill Thoen

unread,
Aug 11, 2011, 4:54:03 PM8/11/11
to mapi...@googlegroups.com
On 8/11/2011 9:53 AM, Uffe Kousgaard wrote:
GUI - GUID. Not quite the same. In fact 25% of the word :-)

I don't know if this applies to all languages, but words written in English can be understood by reading perhaps only a fraction of any word. As long as the length is right and the first and last letters are spelled correctly, you don't have to read the middle ones to know what is being said. For example, I bet you can read and understand this at nearly the same speed as you can when the spelling is perfect:

“It deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist and lsat ltteer be at the rghit pclae. The rset can be a total mses and you can sitll raed it wouthit porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe.”

OTOH, sometimes you've got to read the entire word.

zer...@gmail.com

unread,
Aug 11, 2011, 5:43:02 PM8/11/11
to MapInfo-L
The truth is, I almost confused when Bill answered GUID with "Dialog", does it even had been mentioned (GUID) in help files? I re-opened, then guess what? None..

So I just wait for the one who asked to comment, instead the person asking the question Uffe give his comment. That makes me more lost. GUI - GUID?

I thought GUID was referring to "Globally Unique Identifier". Now the war of words has begin.

So Peter, what are you asking about? a User Interface or a Unique Identifier?


Happy fasting (for those who are celebrating)..
Regards,
Zery

Sent from my BlackBerry®
powered by Sinyal Kuat INDOSAT


From: Bill Thoen <bth...@gisnet.com>
Date: Thu, 11 Aug 2011 14:54:03 -0600
Subject: Re: [MI-L] How to make a GUID?
Message has been deleted
Message has been deleted

robert crossley

unread,
Aug 11, 2011, 6:34:44 PM8/11/11
to mapi...@googlegroups.com

If it is a guid, this article shows how to use an API call to generate a guid.  It is easy enough to incorporate this into MapBasic.

 

http://support.microsoft.com/kb/176790

 

I have to do the same at some point soon, but am not going to get to it today.  I will do something with it if nobody else can help.

 

Rob.

 

From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of zer...@gmail.com
Sent: Friday, 12 August 2011 7:46 AM
To: MapInfo-L
Subject: Re: [MI-L] How to make a GUID?

 

The truth is, I almost confused when Bill answered GUID with "Dialog", does it even had been mentioned (GUID) in help files? I re-opened, then guess what? None..

So I just wait for the one who asked to comment, instead the person asking the question Uffe give his comment. That makes me more lost. GUI - GUID?

I thought GUID was referring to "Globally Unique Identifier". Now the war of words has begin.

So Peter, what are you asking about? a User Interface or a Unique Identifier?


Happy fasting (for those who are celebrating)..
Regards,
Zery

Sent from my BlackBerry®
powered by Sinyal Kuat INDOSAT


From: Bill Thoen <bth...@gisnet.com>

Date: Thu, 11 Aug 2011 14:54:03 -0600

Subject: Re: [MI-L] How to make a GUID?

 

On 8/11/2011 9:53 AM, Uffe Kousgaard wrote:

--

You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

Bill Thoen

unread,
Aug 11, 2011, 7:25:35 PM8/11/11
to mapi...@googlegroups.com
On 8/11/2011 3:43 PM, zer...@gmail.com wrote:
The truth is, I almost confused when Bill answered GUID with "Dialog", does it even had been mentioned (GUID) in help files? I re-opened, then guess what? None..

So I just wait for the one who asked to comment, instead the person asking the question Uffe give his comment. That makes me more lost. GUI - GUID?

I thought GUID was referring to "Globally Unique Identifier". Now the war of words has begin.

Well either way, I answered this question once before in this forum (search the archives for UUID though), but to make up for my misreading this one, here's some mapbasic code to build these GUID or UUID. The real thing depends on some machine parameters, but you can implement it using just a random number generator as specified in RFC 4122.

The attached MapBasic implementation was translated (by me) from the original javascript code by Kevin Hakanson that he posted on ServerFault. The URLs are in the source. I've compiled it with 7.5 which ought to be old enough for anyone.

Basically you run it and it produces a GUII. Like snow flakes,  each one is individually crafted with all the care and individual attention that only a computer can deliver.


- Bill Thoen


guid.mb
guid.MBX

Bill Thoen

unread,
Aug 11, 2011, 10:17:10 PM8/11/11
to MapInfo-L
I just noticed an "off-by-one" bug in the source code I uploaded.
Change the following line from:
rn = Int( Rnd(1) * 16.0 )
to:
rn = Int( Rnd(1) * 16.0 ) + 1

and that'll fix those short UUID's

- Bill Thoen

Mats Elfström

unread,
Aug 12, 2011, 1:04:05 AM8/12/11
to mapi...@googlegroups.com
Hi All!
As a side note, FME has a function to create a georeferenced UID, called a GOID (Geographic Object IDentifier).
It returns a 128-bit GOID for the feature as 32 hex digits in an ASCII string. The first 16 characters correspond to the position, the next 10 to the time, the next 4 to the sequence number, and the final 2 to the checksum.
I have used it recently in an FME script to create a UID for a large number of points that were without any identifer at all.

A complete description of the composition of the string and its parts can be found here
http://docs.safe.com/fme/html/FME_FunctionsFactories/fft_help1/func_goid.htm

If someone were to write a MapBasic function for a UUID, this might be an interesting idea to work from.

Regards, Mats.E

2011/8/12 Bill Thoen <bth...@gisnet.com>

- Bill Thoen

--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en



--
______________________________________________
Mats Elfström, Väpplingvägen 21, SE-227 38 LUND, Sweden
tel: +46 46 145959 / mob: +46 70 595 39 35
alt e-mail: mats.e...@telia.com


ssim...@baltometro.org

unread,
Aug 13, 2011, 8:35:23 PM8/13/11
to mapi...@googlegroups.com

I have some code that calls the Windows API functions for generating GUIDs and converting them to strings.  If I’m not inundated Tuesday when I get back, I’ll post it (Although a gentle reminder would be appreciated).

 


Spencer

Peter Hollebeek

unread,
Aug 25, 2011, 4:48:29 AM8/25/11
to MapInfo-L
Hi Bill

Thanks, sorry for the misunderstanding about my question I will use
your solution most appreciated!
About GUID or not to UUID Global is complex enough for me ;)

Peter

On 12 Aug., 01:25, Bill Thoen <bth...@gisnet.com> wrote:
> On 8/11/2011 3:43 PM,zer...@gmail.comwrote:The truth is, I almost confused when Bill answered GUID with "Dialog", does it even had been mentioned (GUID) in help files? I re-opened, then guess what? None..
>  guid.mb
> 2KVisDownload
>
>  guid.MBX
> 3KVisDownload

robert crossley

unread,
Aug 25, 2011, 5:01:06 AM8/25/11
to mapi...@googlegroups.com
Thanks Bill,

I had missed your answer, and had gone done adapting an API function, with
no success. Will use your code to do it instead.

Rob.

-----Original Message-----
From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On

Hi Bill

Peter

--

Bill Thoen

unread,
Aug 25, 2011, 5:00:03 PM8/25/11
to mapi...@googlegroups.com
Rob, Peter  (and everyone who's planning on using this code),

There is a odd situation that results in duplicate keys. Putting the business end of this algorithm in a loop cycling faster than 400 msec will produce duplicate keys until the random number genrator can catch up. If you slow the loop down to about 500-600 msecs, everything works fine. I'm not sure that the problem is with the Random number routime, but it looks like that's where the problem lay. It's machine dependent too.  My older machines run run this as is with no problems, but my newer machines have to be explicitly slowed down or the problem shows up.

So if you can make this happen on your machine and you find out what's causing it, please let me know sometime.

Uffe Kousgaard

unread,
Aug 25, 2011, 5:22:14 PM8/25/11
to mapi...@googlegroups.com
Hi Bill,

It sounds as if the random number generator simply reads the system clock, which isn't updated every fraction of a msec.

Perhaps it is about time, that MapInfo gets updated with something slightly more modern.

I created an external DLL a long time ago with a better generator and examples of how it looks when you are using either the built-in or the better one in the DLL:
http://www.routeware.dk/download/randompoints.zip

Regards
Uffe

Bill Thoen wrote:

Bill Thoen

unread,
Aug 25, 2011, 7:08:52 PM8/25/11
to mapi...@googlegroups.com
On 8/25/2011 3:22 PM, Uffe Kousgaard wrote:
Hi Bill,

It sounds as if the random number generator simply reads the system clock, which 
isn't updated every fraction of a msec.

Oh, yeah... Of course!! That must be it. Good call! I forgot that the clock is called as part of the process in generating random numbers. It also explains why it appeared "threaded" with two process going on at the same time. And if I recall correctly the default timer can't resolve time into increments smaller than a about half a second. I guess the problem is that on a modern fast machine I can produce about 6 UUIDs a second, but I can get only 1-2 new random numbers in that amount of time. That fits the results and explains the behavior, and leaves nothing unanswered, so until I get time to verify that, that's the current theory in which I'm going to believe.

Just in case anyone's looking for a hair-splitting timer, here's a good summary of the more modern timing functions in a Windows system: http://stackoverflow.com/q/49668. Apparently, you can now resolve time into the  microsecond range with the new 64-bit machines


I created an external DLL a long time ago with a better generator and examples 
of how it looks when you are using either the built-in or the better one in the DLL:
http://www.routeware.dk/download/randompoints.zip
This is a good random number generator (RNG). It's just about as fast as MapInfo's RNG and does a MUCH better job of placing random points on a map. The images below are the result of some tests I ran  a while ago. These two yellow dot images are 10,000 points produced with Uffe's improved RNG on the left and 10,000 points produced with MapInfo's RNG. You can clearly see a linear bias in MapInfo's. The routine MapInfo's using may pass its Chi-square test and other statistical measures of randomness, but as you can see, it's not random. If you want good spatial randomness, Uffe's routine is the one to use.
Random in two flavors

Bill Thoen

unread,
Aug 25, 2011, 7:26:26 PM8/25/11
to mapi...@googlegroups.com
Let's try this again including the images

I created an external DLL a long time ago with a better generator and examples 
of how it looks when you are using either the built-in or the better one in the DLL:
http://www.routeware.dk/download/randompoints.zip
This is a good random number generator (RNG). It's just about as fast as MapInfo's RNG and does a MUCH better job of placing random points on a map. The images below are the result of some tests I ran  a while ago. These two yellow dot images are 10,000 points produced with Uffe's improved RNG on the left and 10,000 points produced with MapInfo's RNG. You can clearly see a linear bias in MapInfo's. The routine MapInfo's using may pass its Chi-square test and other statistical measures of randomness, but as you can see, it's not random. If you want good spatial randomness, Uffe's routine is the one to use.examples of test results

ssim...@baltometro.org

unread,
Aug 26, 2011, 11:55:52 AM8/26/11
to mapi...@googlegroups.com

I’ve been wondering what people have against the Windows API’s CreateGUID function, but It looks like this thread has moved off the topic of creating GUIDs and on to random number generators.  

 

Which is funny because I’ve just been leafing through the old programming chestnut “Numerical Recipes in C++”, which has a chapter on different random number generators to meet different requirements. 

 

MapInfo’s random number generator is probably just the operating system’s generator  or some similar linear congruence generator derived from Knuth, which the “Numerical Recipes” authors characterize as “usually botched”.

 


Spencer

--

image001.png
Reply all
Reply to author
Forward
0 new messages