Generating a GUID

BlitzMax Forums/BlitzMax Programming/Generating a GUID

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I like your approach in using the memory address, but I don't want to get into using the IP address because of Privicy problems that other GUID systems have had.

I have tried the following code, but it appears to run too fast, as the numbers are not random enough...

SuperStrict
For Local t%=1 To 10
	Print createguid()
Next

For Local t%=1 To 10
	Print createguid( True )
Next


'# Create a random GUID (with optional dashes)
'# NOT compatible with the Windows one.
Function createGUID$( lDashes% = False)
Local guid$ = ""
Local nibble%
Const HEXDIGIT$ = "0123456789ABCDEF"
	SeedRnd MilliSecs()
	For Local digit% = 1 To 32
		nibble = Int( Rnd(16) )
		guid:+ HEXDIGIT[nibble..nibble+1]
	Next
	If lDashes Then
		guid = guid[..8]+"-"+guid[8..12]+"-"+guid[12..16]+"-"+guid[16..20]+"-"+guid[20..]
	End If
Return "{"+guid+"}"
End Function

Alternatively I can move the SeedRnd command to the top, but that kind of defeats the object of having all the code in one place...