thx
// randomString returns a pseude-random ASCII string which contains at least the specified number of bits of entropy// the return value is a string of length ⌈bits/6⌉ of characters from the base64 alphabetfunction randomString(bits){var chars,rand,i,retchars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'ret=''// in v8, Math.random() yields 32 pseudo-random bits (in spidermonkey it gives 53)while(bits > 0){rand=Math.floor(Math.random()*0x100000000) // 32-bit integer// base 64 means 6 bits per character, so we use the top 30 bits from rand to give 30/6=5 characters.for(i=26; i>0 && bits>0; i-=6, bits-=6) ret+=chars[0x3F & rand >>> i]}return ret}
--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
you could do something like this maybe?randomString(64)// randomString returns a pseude-random ASCII string which contains at least the specified number of bits of entropy// the return value is a string of length ⌈bits/6⌉ of characters from the base64 alphabetfunction randomString(bits){var chars,rand,i,retchars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'ret=''// in v8, Math.random() yields 32 pseudo-random bits (in spidermonkey it gives 53)while(bits > 0){rand=Math.floor(Math.random()*0x100000000) // 32-bit integer// base 64 means 6 bits per character, so we use the top 30 bits from rand to give 30/6=5 characters.for(i=26; i>0 && bits>0; i-=6, bits-=6) ret+=chars[0x3F & rand >>> i]}return ret}
It depends on the UUID version you want:
http://en.wikipedia.org/wiki/Universally_Unique_Identifier
I'm guessing that by the way you wrote your question that you were
thinking something along the lines of version 1 or version 2 uuids.
Since version 4 is just made of random numbers it would certainly be
possible to generate a "genuine" version 4 uuid.
I think if you want one of the other versions you might have to write
some C bindings to something available on the machine. But I don't
know about that.
On Feb 9, 4:59 am, Benjamin Thomas <bam.tho...@gmail.com> wrote:
Here is a very simple binding which uses libuuid which is a part of
e2fsprogs,
so it should be available on every system
http://bitbucket.org/nikhilm/uuidjs
Hope it does what you need, since it generates only string uuids right
now.
-Nikhil
On Mar 17, 1:25 pm, Nikhil <nsm.nik...@gmail.com> wrote:
> On Mar 17, 10:27 pm, John Wright <mrjjwri...@gmail.com> wrote:
>
> > Did you ever create aguidbinding for node? I need one now too, :).
sys.exec("uuidgen", function(err, stdout, stderr) {
sys.puts(stdout);
});
Check out the Math.uuid.js script I wrote (link at top of this page):
http://www.broofa.com/2008/09/javascript-uuid-function/
The script provides three separate implementations, all standalone.
And the test page includes a performance test that you can run. On my
dinky lil' MacBook the Math.uuidFast method does ~100K guids/second.
- rwk
On Mar 17, 11:10 am, Zachary Zolton <zachary.zol...@gmail.com> wrote:
> I have done something like this on Linux and Mac OS X:
>
> sys.exec("uuidgen", function(err, stdout, stderr) {
> sys.puts(stdout);
>
> });
On Mar 17, 10:24 pm, Robert Kieffer <bro...@gmail.com> wrote:
> Just out of curiousity, how manyguid'sdo you need to generate?
>
> Check out the Math.uuid.js script I wrote (link at top of this page):http://www.broofa.com/2008/09/javascript-uuid-function/
>
> The script provides three separate implementations, all standalone.
> And the test page includes a performance test that you can run. On my
> dinky lil' MacBook the Math.uuidFast method does ~100K guids/second.
>
> - rwk
>
> On Mar 17, 11:10 am, Zachary Zolton <zachary.zol...@gmail.com> wrote:
>
>
>
> > I have done something like this on Linux and Mac OS X:
>
> > sys.exec("uuidgen", function(err, stdout, stderr) {
> > sys.puts(stdout);
>
> > });
> > On Wed, Mar 17, 2010 at 12:27 PM, John Wright <mrjjwri...@gmail.com> wrote:
> > > Did you ever create aguidbinding for node? I need one now too, :).