<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: UUID generator in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/UUID-generator/m-p/226067#M44862</link>
    <description>&lt;P&gt;Here is a method to create a UUID:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;newuuid = function({},
	//following procedure here: https://www.cryptosys.net/pki/uuid-rfc4122.html
	strout = "";
	//guid made from 16 hex bytes
	for(i=1, i&amp;lt;=16, i++,
		thisint = random integer(256) - 1;
		thisbyte = right(hex(thisint,"integer"),2);
		if( i == 7, //the four most significant bits of the of the 7th byte are 0100
			thisbyte = char(4) || right(thisbyte,1),
			i == 9, //the two most significant bits of the 9th byte are 01
			//decimal to binary
			bin = "";
			value = thisint;
			While(value,
				bin = Char(Modulo(Num(value), 2)) || bin;
				value = Floor(value / 2);
			);
			//fix digits
			bin = right(bin,8,"0");
			bin = "10" || right(bin, 6);
			//back to decimal
			dec = 0;
			While(length(bin) &amp;gt; 0,
				dec = dec + (num(left(bin, 1))*2)^(num(length(bin))-1);
				bin = right(bin, length(bin) - 1);
			);
			//to hex
			thisbyte = right( hex( dec, "integer" ), 2 );
		);
		strout = strout || thisbyte;
	);
	//format output
	substr(strout,1,8) || 
		"-" || substr(strout,9,4) || 
		"-" || substr(strout,13,4)|| 
		"-" || substr(strout,17,4) || 
		"-" || substr(strout,21,12);
);

newuuid();&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Disclaimer: I believe I blindly followed &lt;A href="https://www.cryptosys.net/pki/uuid-rfc4122.html" target="_self"&gt;this link&lt;/A&gt; and I didn't do extensive testing...&lt;/P&gt;</description>
    <pubDate>Tue, 17 Sep 2019 13:25:55 GMT</pubDate>
    <dc:creator>ih</dc:creator>
    <dc:date>2019-09-17T13:25:55Z</dc:date>
    <item>
      <title>UUID generator</title>
      <link>https://community.jmp.com/t5/Discussions/UUID-generator/m-p/226012#M44848</link>
      <description>&lt;P&gt;I'm trying to make a standard guid, but hex() is giving me a weird value. I assume it's because of the encoding hex() uses.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone give me some clarity on the below script? Or if someone even just has a UUID function that would be even better.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);
full_h = "123e4567-e89b-12d3-a456-426655440000";
h = substitute(h, "-", "");
n = hex to number(h);
h_again = hex(n);
n_again = hex to number(h);
show(h == h_again, n == n_again);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2019 20:13:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/UUID-generator/m-p/226012#M44848</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2019-09-16T20:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: UUID generator</title>
      <link>https://community.jmp.com/t5/Discussions/UUID-generator/m-p/226043#M44852</link>
      <description>&lt;P&gt;It looks like you already have a guid, and are trying to pack it into another representation.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;guid = "123e4567-e89b-12d3-a456-426655440000";
guid = substitute(guid,"-","");
blob=hextoblob(guid);
show(hex(blob)); //  "123E4567E89B12D3A456426655440000";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;it is not possible to keep the 16 bytes in two 8-byte doubles without hitting missing value issues; the 16 byte blob (or 32 character hex representation) seems reasonable. I don't think JMP exposes a function to create guids; the OS typically forms them from your machine's MAC address, time-of-day, and maybe some other information that should make them nearly unique.&lt;/P&gt;&lt;P&gt;HexToNumber in JSL has a second argument that specifies what sort of encoding the hex represents. I think it may make a special case for exactly 16 hex characters being a double and less than or equal to 8 being a 4-byte integer.&lt;/P&gt;&lt;P&gt;You might find it helpful to load the blob (above) into a matrix of 1-byte unsigned integers if you are trying to disassemble the guid into its components. (blobToMatrix function). You might roll your own guid too,&amp;nbsp;&lt;A href="https://superuser.com/questions/892700/is-there-a-way-to-get-only-the-ethernet-mac-address-via-command-prompt-in-window" target="_self"&gt;https://superuser.com/questions/892700/is-there-a-way-to-get-only-the-ethernet-mac-address-via-command-prompt-in-window&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://en.wikipedia.org/wiki/Universally_unique_identifier" target="_self"&gt;https://en.wikipedia.org/wiki/Universally_unique_identifier&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2019 21:13:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/UUID-generator/m-p/226043#M44852</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2019-09-16T21:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: UUID generator</title>
      <link>https://community.jmp.com/t5/Discussions/UUID-generator/m-p/226044#M44853</link>
      <description>&lt;P&gt;I wasn't trying to pack it into a different representation.&amp;nbsp; I was actually just trying to test with a random 128 bit number and noticing that two VERY different sized hex strings were coming out to be the same number and was trying to figure out how.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or maybe more succinctly.&amp;nbsp; Why is this true?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;hextonumber("47B23E4567E89B13") == hextonumber("123e4567e89b12d3a456426655440000")&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Sep 2019 21:23:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/UUID-generator/m-p/226044#M44853</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2019-09-16T21:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: UUID generator</title>
      <link>https://community.jmp.com/t5/Discussions/UUID-generator/m-p/226045#M44854</link>
      <description>&lt;P&gt;OK, if you give it exacly 16 hex digits, it tries to make an IEEE double. Otherwise it builds an integer, probably in the 53-bit part of a double, and if there are more than about 53/4 (13?) hex digits it both loses precision and displays as if it were a double. None of that is useful for what you are trying to do.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2019 21:36:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/UUID-generator/m-p/226045#M44854</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2019-09-16T21:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: UUID generator</title>
      <link>https://community.jmp.com/t5/Discussions/UUID-generator/m-p/226046#M44855</link>
      <description>&lt;P&gt;haha.&amp;nbsp; I'll have to look that stuff up.&amp;nbsp; Thanks for the help.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I could run under the assumption the user has powershell and just get it through that.&amp;nbsp; I'd have to write a mac equivalent though.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);
create_uuid = function({}, 
	{DEFAULT LOCAL},
	txt = "";
	if(hostis("Windows"), 
		logtxt = logcapture(
			txt = Run Program(executable("Powershell.exe"), 
				Options( {"[guid]::NewGuid()"} ),
				ReadFunction( "text" )
			);
		);
	, //else 
		throw("I don't think Apple has powershell");
	);
	
	if(txt != "", 
		uuid = regex(txt, "[\w\d]{8}-[\w\d]{4}-[\w\d]{4}-[\w\d]{4}-[\w\d]{12}");
		return(uuid);
	, // elif
		Contains(logtxt, "RunProgram Error"), 
		throw(trim(logtxt));
	, //else
		throw("Couldn't find UUID");
	);
);
create_uuid();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2019 21:44:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/UUID-generator/m-p/226046#M44855</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2019-09-16T21:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: UUID generator</title>
      <link>https://community.jmp.com/t5/Discussions/UUID-generator/m-p/226047#M44856</link>
      <description>&lt;P&gt;And the answer to the question:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2.4249434048109e+37 is a double precision number, represented in hex as the left-hand-side of your question. The huge hex value on the right side is an integer that is approximately the same value. It would need a lot more than 53 or 64 bits to accurately represent it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe the hex to number function should warn about the loss of precision.&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/11257"&gt;@EvanMcCorkle&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2019 21:53:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/UUID-generator/m-p/226047#M44856</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2019-09-16T21:53:43Z</dc:date>
    </item>
    <item>
      <title>Re: UUID generator</title>
      <link>https://community.jmp.com/t5/Discussions/UUID-generator/m-p/226048#M44857</link>
      <description>&lt;P&gt;Ahh, I see.&amp;nbsp; Same reason why&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;hextonumber("123e4567e89b12d3a456426655440001") == hextonumber("123e4567e89b12d3a456426655440000")
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Sorry if this was actually two different questions.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2019 21:51:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/UUID-generator/m-p/226048#M44857</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2019-09-16T21:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: UUID generator</title>
      <link>https://community.jmp.com/t5/Discussions/UUID-generator/m-p/226067#M44862</link>
      <description>&lt;P&gt;Here is a method to create a UUID:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;newuuid = function({},
	//following procedure here: https://www.cryptosys.net/pki/uuid-rfc4122.html
	strout = "";
	//guid made from 16 hex bytes
	for(i=1, i&amp;lt;=16, i++,
		thisint = random integer(256) - 1;
		thisbyte = right(hex(thisint,"integer"),2);
		if( i == 7, //the four most significant bits of the of the 7th byte are 0100
			thisbyte = char(4) || right(thisbyte,1),
			i == 9, //the two most significant bits of the 9th byte are 01
			//decimal to binary
			bin = "";
			value = thisint;
			While(value,
				bin = Char(Modulo(Num(value), 2)) || bin;
				value = Floor(value / 2);
			);
			//fix digits
			bin = right(bin,8,"0");
			bin = "10" || right(bin, 6);
			//back to decimal
			dec = 0;
			While(length(bin) &amp;gt; 0,
				dec = dec + (num(left(bin, 1))*2)^(num(length(bin))-1);
				bin = right(bin, length(bin) - 1);
			);
			//to hex
			thisbyte = right( hex( dec, "integer" ), 2 );
		);
		strout = strout || thisbyte;
	);
	//format output
	substr(strout,1,8) || 
		"-" || substr(strout,9,4) || 
		"-" || substr(strout,13,4)|| 
		"-" || substr(strout,17,4) || 
		"-" || substr(strout,21,12);
);

newuuid();&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Disclaimer: I believe I blindly followed &lt;A href="https://www.cryptosys.net/pki/uuid-rfc4122.html" target="_self"&gt;this link&lt;/A&gt; and I didn't do extensive testing...&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2019 13:25:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/UUID-generator/m-p/226067#M44862</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2019-09-17T13:25:55Z</dc:date>
    </item>
  </channel>
</rss>

