Sign in to follow this  
Followers 0
cppman

UNIQUE STRING GENERATOR

49 posts in this topic

#1 ·  Posted (edited)

okay, this function generates a string around 38 characters as a UNIQUE STRING that will never be generated again. Same as a GUID, and everyone was having a pissy fit, so i had to change the name. lol . *the number of characters is going to be different each time.

If i did the math correctly the chances of the same string being chosen again, is:

1 out of 1.408e+082 depending on the date, and computer. (only for Nums and Characters, not sure about just 1, but i guess u'd just devide the number by two...)

so i guess its somewhat uniue, lol. (it should be impossible to generate 2 of the same id's at any time on different computers.)

not sure what u'd really use this for, but i got bored...

Func GenUnique($iType = 1)
    ;(1) = normal - Characters and numbers
    ;(2) = integer - Numbers only
    ;(3) = character - Characters only, a-z, A-Z
    $set1 = Random(round(sqrt(@SEC)), round(sqrt(@SEC*10)), 1)
    $set2 = Random(round(sqrt(DriveGetSerial(@HomeDrive))), random(round(sqrt($set1)), $set1*2, 1),1)
    $set3 = Random(1, 10, 1)*($set1+@MIN+@HOUR)
    $set4 = Random($set1+$set2+$set3, random(2, 5, 1)*($set1+$set2+$set3+@MDAY), 1)
    $finaly = round($set1+$set2+$set3+$set4)+@YEAR
    if $iType = 1 Then
    $set1 = Chr(random(65, 89, 1))
    $set2 = Chr(random(97, 122, 1))
    $set3 = $set1&$set2
    $finaly = $finaly&$set3&DriveGetSerial(@HomeDrive)&$set1&@MIN&@SEC&@MDAY&$set2&@HOUR&@YEAR&$set3
    for $i = 1 to random(1, 10, 1)
        $finaly = $finaly & Chr(random(65, 89, 1))
    Next
    return $finaly
    elseif $iType = 2 Then
    $set1 = random(65, 89, 1)
    $set2 = random(97, 122, 1)
    $set3 = $set1&$set2
    $finaly = $finaly&$set3&DriveGetSerial(@HomeDrive)&$set1&@MIN&@SEC&@MDAY&$set2&@HOUR&@YEAR&$set3
    for $i = 1 to random(1, 10, 1)
        $finaly = $finaly & random(1, 10, 1)
    Next
    return $finaly
Else
        $max = 38
    Dim $avChar[52] ;65 - 90;97-122
        For $i = 0 to 25
            $avChar[$i] = Chr($i+65)
        Next
        For $i = 26 to 51
            $avChar[$i] = Chr($i+71)
        Next
        $set1 = Helper1(@SEC&@MIN&@HOUR&@WDAY&@MDAY&@YEAR&@MON)
        $set2 = Helper1(random(@SEC, random(@SEC*2, @SEC*5), 1))
        $set3 = Helper1(DriveGetSerial(@HomeDrive)*@MIN)
        $set4 = Helper1(sqrt(DriveGetSerial(@HomeDrive)+@SEC))
        return Fixer($set1&$set4&$set2&$set3)
EndIf

EndFunc
Func Helper1($str)
            $max = 38
    Dim $avCur[$max]
        $string1 = StringSplit($str, "")
        For $i = 1 to $string1[0]
        Select
            Case $string1[$i]   = "1"
                $avCur[$i]   = Chr(random(65, random(65, 90, 1), 1))
            Case $string1[$i]   = "2"
                $avCur[$i]   = Chr(random(97, random(97, 122, 1), 1))
            Case $string1[$i]   = "3"
                $avCur[$i]   = Chr(random(65, random(65, 90, 1), 1))
            Case $string1[$i]   = "4"
                $avCur[$i]   = Chr(random(97, random(97, 122, 1), 1))
            Case $string1[$i]   = "5"
                $avCur[$i]   = Chr(random(65, random(97, 122, 1), 1))
            Case $string1[$i]   = "6"
                $avCur[$i]   = Chr(random(65, random(65, 90, 1), 1))
            Case $string1[$i]   = "7"
                $avCur[$i]   = Chr(random(65, random(97, 122, 1), 1))
            Case $string1[$i]   = "8"
                $avCur[$i]   = Chr(random(65, 90, 1))
            Case $string1[$i]   = "9"
                $avCur[$i]   = Chr(random(65, random(65, 90, 1), 1))
            Case $string1[$i]   = "0"
                $avCur[$i]   = Chr(random(97, random(97, 122, 1), 1))
        EndSelect
    Next
    local $string
        For $i =  1 to $string1[0]
            $string &= $avCur[$i]
        Next
        
        Return $string
EndFunc
    
Func Fixer($string)
    $str = StringSplit($string, "")
    for $i = 1 to $str[0]
        ;32 - 64
        for $a = 32 to 64
            if $str[$i] = Chr($a) Then
                $str[$i] = ""
            Else
            EndIf
            for $b = 91 to 96
                if $str[$i] = Chr($B) Then
                    $str[$i] = ""
                EndIf
            Next
        Next
    Next
    Local $text
    For $i = 1 to $str[0]
        $text &= $str[$i]
    Next
    Return $text

EndFunc
oÝ÷ Ù&¦¦W²æ y«­¢+Ø)5Í   ½à À°ÅÕ½Ðí ½Ñ 
¡ÉÑȹ9ÕµÉÌÅÕ½Ðì°¹U¹¥ÅÕ Ä¤¤)5Í   ½à À°ÅÕ½Ðí9ÕµÉÌ=¹±äÅÕ½Ðì°¹U¹¥ÅÕ È¤¤)5Í   ½à À°ÅÕ½Ðí
¡ÉÑÉ̽¹±äÅÕ½Ðì°¹U¹¥ÅÕ Ì¤¤
Edited by CHRIS95219

Share this post


Link to post
Share on other sites



Cool...

I have a similar one which will generate only unique nos....no alphabets...

Also if we have the option of selecting no of chars for output it will be great....

Thanks

-Bala

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I was using the below code to generate unique nos for me for a long time...LOL.

now i will use yours...

Func _GenerateUniqueDocID()
    Return (@WDAY & @MDAY & @HOUR & @MIN & @SEC)
EndFunc   ;==>_GenerateUniqueDocID

-Bala

Edited by Balachander K

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

thanks,

i dunno about selecting how many characters to output... im not sure how to add that without redoing all my code. lol.

Updated First post with code for 3 options. Character & Numbers or Numbers only, and Characters Only .

got the character only way :D

Edited by CHRIS95219

Share this post


Link to post
Share on other sites

@Chris this is a cool scrap.. Im defentily gonna use it in some of my scripts


My Scripts:Radioblog Club Music DownloaderOther stuff:Fun movieIm serious read the help file it helps :PFight 'Till you drop. Never stop, You Cant give up. Til you reach the top Fight! you’re the best in town Fight!

Share this post


Link to post
Share on other sites

Did you actually use a Globally Unique Identifier algorithm or did you just come up with your own algorithm that makes what looks like GUIDs? It's not a GUID unless it is unique on the planet (Globally). That means it needs to use a standard algorithm. The fact that I see comments asking about different numbers of characters in the string concerns me and makes me think it may not be a standard algorithm. GUIDs have a fixed length of bytes (A length which escapes me at the moment), the number of characters doesn't change as a result.

Share this post


Link to post
Share on other sites

;~ 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.

quote from msdn


SciTE for AutoItDirections for Submitting Standard UDFs

 

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

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

um.. No i did'nt go by "standards", *wonder what gave that away. lol*

It is pretty unique, goes by the serial number of the hard drive which narrows it down quite a bit, plus im sure the date will never be the same twice which also makes it unique. well i hope the same date never happens again.

I was'nt trying to go by any standard, but it is almost impossible(i think) to generate this ID again if your using $iType 1...

it generates a random string, and is most likely going to be unique as long as the same date does'nt occur twice....

why should it have to follow any standards?

i hate when people bring up standards(no offense)... as in,

"The new standards for programming language include OOP..." which bugs me.

GUID could have also stood for anything....

the one purpose this is meant to do is, generate a random string that is almost impossible to generate again.

Edited by CHRIS95219

Share this post


Link to post
Share on other sites

Hey Chris!

Nice code.

BTW, you should work on a scrap to stop time.

maybe in c#? or in vb.net,

might show someone there standards. uh, *common sinse* but... Wasn't it already obvious that it wasn't microsoft's version? Hay, the computer didn't crash! So, thanks for not "following standards."

Laters,

~~TheCreator~~

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

um.. No i did'nt go by "standards", *wonder what gave that away. lol*

It is pretty unique, goes by the serial number of the hard drive which narrows it down quite a bit, plus im sure the date will never be the same twice which also makes it unique. well i hope the same date never happens again.

I was'nt trying to go by any standard, but it is almost impossible(i think) to generate this ID again if your using $iType 1...

it generates a random string, and is most likely going to be unique as long as the same date does'nt occur twice....

You sound real confident.

why should it have to follow any standards?

i hate when people bring up standards(no offense)... as in,

"The new standards for programming language include OOP..." which bugs me.

Deal with it. If you want to dabble in this field, standards are part of it. If you don't like standards, get lost. Standards are very important. Without them, every Joe-nobody would come along and write their own GUID generator and pretty soon GUIDs would be worthless. While it may be true that each individual generator makes unique IDs, there is no guanrantee that any particular ID is unique compared to the output of another other generator. Can you guarantee that your generator will never produce an ID that the Microsoft generator has already generated or will generate in the future?

GUID could have also stood for anything....

Nope, I'm afraid not. GUID has a definition, Globally Unique Identifier. It also has an algorithm. People will be looking specifically for a GUID generator that conforms to the standard Microsoft uses and they're going to find this thread which does not provide that.

the one purpose this is meant to do is, generate a random string that is almost impossible to generate again.

That's fine. Don't call it a GUID/UUID/CLSID since it's not, at least not by the industry/de-facto standard. Those terms have specific algorithms associated with them and provide certain guarantees *when using those algorithms*. You're using the same name with a different algorithm. Anybody using this thinking they are generating the same type of GUID as guiidgen.exe has been needless mislead.

Edit: Fixed typo.

Edited by Valik

Share this post


Link to post
Share on other sites

Hello.

Well, if anyone decided to search for "guid" they woudl see a developer, who insists on acting like a little kid. OK, The "STANDARdS" weren't followd. But, why should everyone follow standards? If we always do it the way Microcrap says we should, then there won't be any place for creativeness and inovative ideas that may make something beyond what Microsoft has. So, while we have those developers who follow every standard possible, and spend there life studying ISO rules, instead of actually developing, there are those of us who actually get off our asses, and do soemthing creative. Also, if we did it the Microsoft way, after you generated the string, you should have gotten some soart of error, that just didn't sorta fit in with the program.

Thanks,

~~TheCreator~~

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I never once said my GUID was the the same GUID as Microsoft's GUID's.

My UDF fulfilled the description of Globally Unique Identifier. If microsoft happens to change the way there's is to a 38 character key, that is not my problem. It creates a 38 digit string like i said in my first post. and thats all.

I do agree that i need to follow standards but not in a UDF that your writing yourself with your own algorithm.

what do u mean don't call it a GUID? Is it copyrighted? no. GUID has a very broad description. Globally Unique Identifier. What does that mean? An ID that will never be generated again..

Flying a kite with a key attached to it is stupid huh?

Edited by CHRIS95219

Share this post


Link to post
Share on other sites

Hello.

Well, if anyone decided to search for "guid" they woudl see a developer, who insists on acting like a little kid. OK, The "STANDARdS" weren't followd. But, why should everyone follow standards? If we always do it the way Microcrap says we should, then there won't be any place for creativeness and inovative ideas that may make something beyond what Microsoft has. So, while we have those developers who follow every standard possible, and spend there life studying ISO rules, instead of actually developing, there are those of us who actually get off our asses, and do soemthing creative. Also, if we did it the Microsoft way, after you generated the string, you should have gotten some soart of error, that just didn't sorta fit in with the program.

Thanks,

~~TheCreator~~

You're quite the idiot, aren't you? You infer a lot, assume a lot and know very little about a subject you're attempting to argue about. Why don't you piss off?

I never once said my GUID was the the same GUID as Microsoft's GUID's.

You never once said it wasn't, either.

My UDF fulfilled the description of Globally Unique Identifier. If microsoft happens to change the way there's is to a 38 character key, that is not my problem. It creates a 38 digit string like i said in my first post. and thats all.

No, your function is a globally unique identifier. It is not a Globally Unique Identifier. One is an adjective, the other is a noun. I suggest you confirm the difference between the two as it is important.

I do agree that i need to follow standards but not in a UDF that your writing yourself with your own algorithm.

I never said make it follow the standard, I simply said don't call it a GUID unless it's a GUID.

what do u mean don't call it a GUID? Is it copyrighted? no. GUID has a very broad description. Globally Unique Identifier. What does that mean? An ID that will never be generated again..

Again, back to the noun versus adjective thing. See above for that.

Flying a kite with a key attached to it is stupid huh?

Let me give you a hypothetical example that is similar. Say you have a car. Imagine your car breaks a part. Imagine I manufactor rubber car part replicas. Imagine you know nothing about cars. My rubber car part is called the same thing as the real car part. My rubber car part looks the same. Since you don't know any better, you won't know the difference between the real part and the rubber part because they have the same name. Imagine I put this rubber part in your car. What do you think is going to happen?

Now imagine somebody searching the AutoIt forum for a GUID generator not really knowing what a GUID is other than they need one. Now imagine them putting it into their application thinking it's the same thing they need. Now imagine their confusion when it doesn't work.

If you do not understand any of this, then I request that you please stop programming. Now. It's really just common sense. When things have a definition already, a definition understood and recognized by thousands of programmers, you don't just suddenly write some new and similar thing and name it the same thing. It's really just a simple matter of sitting down and going, "Okay, this is the name I want, is that name being used for stuff? Yes, then I better not use that name because my code will be confused with that."

Share this post


Link to post
Share on other sites

It's really as simple as has been said. Your script creates identifiers that may be globally unique, but it's not a GUID in the commonly understood sense.

It's a good idea to change the title of this thread to something else to avoid confusion.

Case in point, I opened this thread excited to see a real GUID generator written in AutoIt (though I did have reservations). While I'm not disappointed with the ultimate usefulness of your function, it's definitely not what I expected to find.

Were I not a programmer with at least a basic understanding of Windows API, I wouldn't have known the difference - and that is very clearly the point your detractor is (apparently very brutally) trying to make, here.

-S


(Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]

Share this post


Link to post
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
Sign in to follow this  
Followers 0