Jeff Craig![]()
A UUID Generator in JavaScript. This version uses Math.random and bitwise operations, so it should work in any environment, even a quite old one.
Many pages have been written about why Math.random shouldn't be used for 'serious programming'. The points are well taken, Math.random is not guaranteed to be a cryptographically secure PRNG. If, for your usage, you need real guarantees, this version will not work, and you should do UUID generation server-side, which would allow you to generate UUIDs not using the PRNG version anyway. For my usage, this is 'good-enough', but you should evaluate that for your own application.
There are a few improvements coming. The WHATWG has a proprosal for a window.crypto object, which, in addition to strongly-typed arrays, will allow this to work fast and more correctly, and with Loader's conditional loading, we can use that method in versions that support it.
I am seriously considering writing a pure JS PRNG that will,while being dramatically slower, provide far more quality in the random-number generation, that the UUID generator could optionally use. Not as good a solution as window.crypto, but we'll see what the adoption curve on that feature looks like before I take this step.
Future improvements:
<script src="http://yui.yahooapis.com/3.5.0pr1/build/yui/yui-min.js"></script>YUI({
//Last Gallery Build of this module
gallery: 'gallery-2012.01.25-21-14'
}).use('gallery-uuid', function(Y) {
var uuid = Y.Crypto.UUID();
});
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info