[B_UUID]

Description

Link: [B_UUID]
Author: Douglas Burchard
Category: Custom Tag
Version: 8.5.x
License: Public Domain
Posted: Sep. 25, 2009
Updated: Sep. 25, 2009
More by this author...
This custom prototype returns a version 4 (random) Universally Unique Identifier (UUID). For more information on UUIDs, please read the Wikipedia entry, currently at: http://en.wikipedia.org/wiki/uuid

Parameters

none


Sample Usage

B_UUID
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// =====================================================================
/*
	B_UUID
	--------------------------------------------------------------------

		===========================================
		| B_UUID
		|
		===========================================
		| Tags
		-------------------------------------------
		| onCreate()						String
		| ToHex(Integer)					String
		| ToChar(Integer)					String
		| GenerateNumber(Integer,Integer)	Integer
		| GenerateUUID()					String
		|

	This custom prototype returns a version 4 (random) Universally Unique
	Identifier (UUID). For more information on UUIDs, please read the 
	Wikipedia entry, currently at:

		http://en.wikipedia.org/wiki/uuid

*/
// ---------------------------------------------------------------------
Define_Type('UUID',
		-NameSpace='B_',
		-Prototype,
		-Description='This custom prototype returns a version 4 (random) ' +
			'Universally Unique Identifier (UUID). For more information ' +
			'on UUIDs, please read the Wikipedia entry, currently at: ' +
			'http://en.wikipedia.org/wiki/uuid.');

	Define_Tag('onCreate');
		Return(String(Self -> GenerateUUID));
	/Define_Tag;

	Define_Tag('ToHex', -Required='d', -EncodeNone);
		Local('r' = (#d % (16)));
		Local('result');
		If((#d - #r) == (0));
			#result = (Self -> ToChar(#r));
		Else;
			#result = ((Self -> ToHex((#d - #r) / (16))) + (Self -> ToChar(#r)));
		/If;
		Return(#result);
	/Define_Tag;

	Define_Tag('ToChar', -Required='n', -EncodeNone);
		Local('alpha' = '0123456789abcdef');
		Return(#alpha -> Get(#n + (1)));
	/Define_Tag;

	Define_Tag('GenerateNumber', -Required='l', -Required='u', -EncodeNone);
		Local('n' = Math_Random(-Lower=(Local('l') - (1)), -Upper=Local('u')));
		#n = ((#n < Local('l')) ? Local('u') | (#n));
		Return(#n);
	/Define_Tag;

	Define_Tag('GenerateUUID', -EncodeNone);
		Local('random_bytes' = String);

		#random_bytes += (Self -> ToHex(_date_msec));
		#random_bytes -> Reverse;
		While((#random_bytes -> Size) < (30));
			#random_bytes += (Self -> ToHex(Self -> GenerateNumber((0), (15))));
		/While;
		#random_bytes -> Lowercase;
		#random_bytes = String_Insert(#random_bytes, -Position=(9), -Text='-');
		#random_bytes = String_Insert(#random_bytes, -Position=(14), -Text='-4');
		#random_bytes = String_Insert(#random_bytes, -Position=(19), -Text=('-' + (Array('8','9','a','b') -> Get(Self -> ToHex(Self -> GenerateNumber((1), (4)))))));
		#random_bytes = String_Insert(#random_bytes, -Position=(24), -Text='-');

		Return(#random_bytes);
	/Define_Tag;

/Define_Type;
// =====================================================================

 

Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net