Generate UUID

I just looked around and wanted to create UUID numbers. Then I noticed, that stuff is already available under Windows in VASmalltalk:

| aStream anGUID |

	aStream := WriteStream on: String new.

	anGUID := OSGuid new.
	anGUID coCreateGuid.
	anGUID printOn: aStream.

	^aStream contents

On the other hand you may also use the members of the OSGuid structure to store the integer values of that UUID.

Today I received an eNail from David Gorisek, which posted a solution working under Linux:

   buf := ByteArray new: 16.
           (PlatformFunction callingConvention: 'C'
               function: 'uuid_generate'
               library: ''
               parameterTypes: #(pointer )
               returnType: #void)
                   callWith: buf.

I tested it under Ubuntu/64 and it works … Thanks to David for this tip !

This entry was posted in Smalltalk. Bookmark the permalink.