/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

/**
 * Returns a random integer between min and max
 */
function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

/**
 * Build a digits code
 */
function digitsCode(size) {
  var s = size;
  var code = "";
  while (s > 0) {
    s--;
    code += getRandomInt(0, 9);
  }
  return code;
}

module.exports = {
  digitsCode: digitsCode
};

@@ -218,329 +218,233 @@
 %22;%0A%0A
-/**%0A * Returns a random integer between min and max%0A */%0Afunction getRandomInt(min, max) %7B%0A  return Math.floor(Math.random() * (max - min + 1)) + min;%0A%7D%0A%0A/**%0A * Build a digits code%0A */%0Afunction digitsCode(size) %7B%0A  var s = size;%0A  var code = %22%22;%0A  while (s %3E 0) %7B%0A    s--;%0A    code += getRandomInt(0, 9);%0A  %7D%0A  return code
+var crypto = require(%22crypto%22);%0A%0A/**%0A * Build a digits code%0A */%0Afunction digitsCode(size) %7B%0A  var nbBytes = Math.ceil(size/2);%0A  return parseInt(crypto.randomBytes(nbBytes).toString(%22hex%22), 16)%0A    .toString().substr(0, size)
 ;%0A%7D%0A

Refactor digitCode to use /dev/urandom instead of Math.random. r=Tarek