[Groonga-commit] groonga/gcs [master] Generate random ID

Back to archive index

null+****@clear***** null+****@clear*****
2012年 8月 2日 (木) 12:09:11 JST


SHIMODA Hiroshi	2012-08-02 12:09:11 +0900 (Thu, 02 Aug 2012)

  New Revision: b4f945e16f93b01f1add35ca03d131ab0c4c876d
  https://github.com/groonga/gcs/commit/b4f945e16f93b01f1add35ca03d131ab0c4c876d

  Log:
    Generate random ID

  Modified files:
    lib/database/domain.js

  Modified: lib/database/domain.js (+8 -1)
===================================================================
--- lib/database/domain.js    2012-08-02 11:47:54 +0900 (f1fdb27)
+++ lib/database/domain.js    2012-08-02 12:09:11 +0900 (596c0dd)
@@ -117,7 +117,14 @@ Domain.prototype = {
     return this.createNewId();
   },
   createNewId: function() {
-    // we must calculate it!
+    var size = 26;
+    var characters = '0123456789abcdefghijklmnopqrstuvwxyz'.split('');
+    var lastIndex = characters.length;
+    var id = '';
+    while (id.length < size) {
+      id += characters[Math.round(Math.random() * lastIndex)];
+    }
+    return id;
   },
 
   get tableName() {
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
Download 



Groonga-commit メーリングリストの案内
Back to archive index