Skip to content

Commit

Permalink
Add in a quick generator for version 4 UUIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Whiteknight committed Dec 1, 2011
1 parent d1b670e commit 983058f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion setup.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ function setup_stable_libraries(var rosella)
"random/Random",
"random/RandomNumber",
"random/randomnumber/BoxMullerNormal",
"random/randomnumber/MersenneTwister"
"random/randomnumber/MersenneTwister",
"random/uuid/V4"
);

// Working with commandline arguments
Expand Down
16 changes: 16 additions & 0 deletions src/random/uuid/V4.winxed
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Rosella.Random.UUID.V4
{
function get()
{
var rand = Rosella.Random.default_uniform_random();
string hex[] = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"];
string s[] = [];
for (int i = 0; i < 36; i++)
s[i] = hex[int(rand.get_range(0, 16))];
s[14] = hex[4];
int s19 = (int(rand.get_range(0, 16)) & 0x03) | 0x08;
s[19] = hex[s19];
s[8] = s[13] = s[18] = s[23] = "-";
return join("", s);
}
}

0 comments on commit 983058f

Please sign in to comment.