[Pkg-javascript-commits] [sockjs-client] 205/434: A bit better implementation of random_number_string

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:14 UTC 2014


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch master
in repository sockjs-client.

commit 97f8b918da2cea8986b09b54557b75105fece239
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Fri Nov 25 13:28:02 2011 +0000

    A bit better implementation of random_number_string
    
    Using Douglas Crockford way of getting prefix zeroes.
---
 lib/utils.js | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lib/utils.js b/lib/utils.js
index a10925c..28bd175 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -15,10 +15,9 @@ utils.random_number = function(max) {
     return Math.floor(Math.random() * max);
 };
 utils.random_number_string = function(max) {
-    var s = ''+utils.random_number(max);
     var t = (''+(max - 1)).length;
-    while (s.length < t) {s = '0' + s;}
-    return s;
+    var p = Array(t+1).join('0');
+    return (p + utils.random_number(max)).slice(-t);
 };
 
 utils.attachMessage = function(listener) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list