Browse files

Add UUID function

  • Loading branch information...
1 parent 562dc1c commit 80bfce4e8ab9334fa1871154c2a650b1dd29ddf5 @pr1001 committed Jun 21, 2011
Showing with 8 additions and 0 deletions.
  1. +8 −0 mathplus.js
View
8 mathplus.js
@@ -317,5 +317,13 @@ var M = {
// based on an equation on Wikipedia: http://en.wikipedia.org/wiki/Closure_(computer_science)
'derivative': function derivative(f, x) {
return (f(x + M.SMALL_NUMBER) - f(x)) / M.SMALL_NUMBER;
+ },
+ // RFC 4122 version 4 UUID
+ // from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
+ 'UUID': function() {
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
+ var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
+ return v.toString(16);
+ });
}
};

0 comments on commit 80bfce4

Please sign in to comment.