Jump to content

Simple UID Generator


Guest Mixture63
 Share

Recommended Posts

Guest Mixture63

;UID Generator by Mixture63

MsgBox(0, "Random UID", GenerateUID())

func GenerateUID()
$Section1 = Hex(Random(0, 256^2, 1), 4) & Hex(Random(0, 256^2, 1), 4)
$Section2 = Hex(Random(0, 256^2, 1), 4)
$Section3 = Hex(Random(0, 256^2, 1), 4)
$Section4 = Hex(Random(0, 256^2, 1), 4)
$Section5 = Hex(Random(0, 256^2, 1), 4) & Hex(Random(0, 256^2, 1), 4) & Hex(Random(0, 256^2, 1), 4)

return "{" & $Section1 & "-" & $Section2 & "-" & $Section3 & "-" & $Section4 & "-" & $Section5 & "}"
EndFunc

I figured I'd seperate this from my other topic because it wasn't attracting any attention. I mean who would see it?

Link to comment
Share on other sites

FYI: For anybody seriously considering using the function as posted, it does not generate true UUID's. The implementation just creates a string that looks like a UUID but it is not guaranteed to be unique across time and space which is the whole point of UUID's.

Link to comment
Share on other sites

Guest Mixture63

FYI: For anybody seriously considering using the function as posted, it does not generate true UUID's. The implementation just creates a string that looks like a UUID but it is not guaranteed to be unique across time and space which is the whole point of UUID's.

Can you give me a link that'll show me the algorithm? I want to make a func myself.

The link you showed me didn't say anything about the algorithim itself.

Link to comment
Share on other sites

;UID Generator by Mixture63

MsgBox(0, "Random UID", GenerateUID())

func GenerateUID()
$Section1 = Hex(Random(0, 256^2, 1), 4) & Hex(Random(0, 256^2, 1), 4)
$Section2 = Hex(Random(0, 256^2, 1), 4)
$Section3 = Hex(Random(0, 256^2, 1), 4)
$Section4 = Hex(Random(0, 256^2, 1), 4)
$Section5 = Hex(Random(0, 256^2, 1), 4) & Hex(Random(0, 256^2, 1), 4) & Hex(Random(0, 256^2, 1), 4)

return "{" & $Section1 & "-" & $Section2 & "-" & $Section3 & "-" & $Section4 & "-" & $Section5 & "}"
EndFunc

I figured I'd seperate this from my other topic because it wasn't attracting any attention. I mean who would see it?

You might also try this, You wll neend beta version of Autoit to run.

#include <GuiConstants.au3>

GuiCreate("test", 420, 331, 198,136 )

GUISetFont(10)

$EditGUID = GuiCtrlCreateInput("", 16, 72, 385, 25)

$ButtonGUID = GuiCtrlCreateButton("GUID", 160, 136, 73, 25)

GuiSetState()

While 1

$msg = GuiGetMsg()

Select

Case $msg=$ButtonGUID

$str=GetGUID()

GUICtrlSetData($EditGUID,$str)

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case Else

;;;

EndSelect

WEnd

Exit

Func GetGUID()

Local $typelib,$str

$typelib=ObjCreate("Scriptlet.TypeLib")

$str=$TypeLib.Guid

Return $str

EndFunc

You might also try this, You wll neend beta version of Autoit to run.

#include <GuiConstants.au3>

GuiCreate("test", 420, 331, 198,136 )

GUISetFont(10)

$EditGUID = GuiCtrlCreateInput("", 16, 72, 385, 25)

$ButtonGUID = GuiCtrlCreateButton("GUID", 160, 136, 73, 25)

GuiSetState()

While 1

$msg = GuiGetMsg()

Select

Case $msg=$ButtonGUID

$str=GetGUID()

GUICtrlSetData($EditGUID,$str)

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case Else

;;;

EndSelect

WEnd

Exit

Func GetGUID()

Local $typelib,$str

$typelib=ObjCreate("Scriptlet.TypeLib")

$str=$TypeLib.Guid

Return $str

EndFunc

seems i need to learn how to post code, another things to do added...LOL
Link to comment
Share on other sites

Guest Mixture63

You might also try this, You wll neend beta version of Autoit to run.

#include <GuiConstants.au3>

GuiCreate("test", 420, 331, 198,136 )

GUISetFont(10)

$EditGUID = GuiCtrlCreateInput("", 16, 72, 385, 25)

$ButtonGUID = GuiCtrlCreateButton("GUID", 160, 136, 73, 25)

GuiSetState()

While 1

$msg = GuiGetMsg()

Select

Case $msg=$ButtonGUID

$str=GetGUID()

GUICtrlSetData($EditGUID,$str)

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case Else

;;;

EndSelect

WEnd

Exit

Func GetGUID()

Local $typelib,$str

$typelib=ObjCreate("Scriptlet.TypeLib")

$str=$TypeLib.Guid

Return $str

EndFunc

seems i need to learn how to post code, another things to do added...LOL

Yea, well thats a generator APP, I just wanted to make a func.

But I like it.

I don't understand what Scriptlet.TypeLib.Guid has to do with generating a Guid. I just thought that was

the Guid of that COM object.

Link to comment
Share on other sites

OK, how much does it cost to higher a crypto-anylist? I can't seem to decipher the article.

;)

That RFC is easy to read. There are lots of others that are far more complicated.

The approach presented by wiredbits is valid. The COM object being used is mentioned here. It basically wraps the Windows API calls necessary to generate the string form of a UUID and returns them for use by a scripting language.

Edited by Valik
Link to comment
Share on other sites

That RFC is easy to read. There are lots of others that are far more complicated.

The approach presented by wiredbits is valid. The COM object being used is mentioned here. It basically wraps the Windows API calls necessary to generate the string form of a UUID and returns them for use by a scripting language.

@LxP,

I meant the link in Valik's post i just quoted ;)

FootbaG
Link to comment
Share on other sites

Valik,

Something is wrong with that link. I tired removing the ''" 's and the double "http://" but it still didn't work.

this works for me: http://www.asp-dev.com/main.asp?page=60

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Can you give me a link that'll show me the algorithm? I want to make a func myself.

The link you showed me didn't say anything about the algorithim itself.

Try the UDF listed here: http://www.autoitscript.com/forum/index.php?showtopic=11865

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Was wondering if Auoit releases any resources used when creating a object..IE $typelib=ObjCreate("Scriptlet.TypeLib").

In VB i see they use Set TypeLib = Nothing, hmm support in scraps ;)

If not I will use the Dllcall func you linked to instead of Scriptlet.TypeLib call.

Thanks

Jim

Link to comment
Share on other sites

Valik,

Something is wrong with that link. I tired removing the ''" 's and the double "http://" but it still didn't work.

Thanks layer. I fixed the link. It was something the forum did because I used ' instead of " to surround the URL. Very strange.
Link to comment
Share on other sites

the following is also posted here http://www.autoitscript.com/forum/index.ph...ndpost&p=115072

Const $ERROR_SUCCESS = 0
Const $RPC_S_OK = $ERROR_SUCCESS
Const $RPC_S_UUID_LOCAL_ONLY = 1824
Const $RPC_S_UUID_NO_ADDRESS = 1739

;~ typedef struct _GUID { 
;~ unsigned long Data1; 
;~ unsigned short Data2; 
;~ unsigned short Data3; 
;~ unsigned char Data4[8];
;~ } GUID, UUID;
;~ Data1 
;~ Specifies the first 8 hexadecimal digits of the UUID. 
;~ Data2 
;~ Specifies the first group of 4 hexadecimal digits of the UUID. 
;~ Data3 
;~ Specifies the second group of 4 hexadecimal digits of the UUID. 
;~ Data4 
;~ Array of eight elements. The first two elements contain the third group of 4 hexadecimal digits of the UUID.
;~ The remaining six elements contain the final 12 hexadecimal digits of the UUID. 

$_GUID = DllStructCreate("uint;ushort;ushort;ubyte[8]")
If @error Then Exit

;~ RPC_STATUS RPC_ENTRY UuidCreate(
;~ UUID __RPC_FAR* Uuid
;~ );

$ret = DllCall("Rpcrt4.dll","ptr","UuidCreate","ptr",DllStructGetPtr($_GUID))
If Not @error Then
If $ret[0] = $ERROR_SUCCESS Then
$uuid = Hex(DllStructGetData($_GUID,1),8) & "-" & _ 
Hex(DllStructGetData($_GUID,2),4) & "-" & _
Hex(DllStructGetData($_GUID,3),4) & "-" & _
Hex(DllStructGetData($_GUID,4,1),2) & Hex(DllStructGetData($_GUID,4,2),2) & "-"
For $x =3 to 8
$uuid = $uuid & Hex(DllStructGetData($_GUID,4,$x),2)
Next
ConsoleWrite($uuid & @LF)
EndIf
EndIf
DllStructDelete($_GUID)
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...