Browse Source

fix tests for random

patch-2
Manuel Araoz 10 years ago
parent
commit
5440baad83
  1. 5
      lib/crypto/random.js
  2. 7
      test/crypto/random.js

5
lib/crypto/random.js

@ -14,7 +14,7 @@ Random.getRandomBuffer = function(size) {
Random.getRandomBufferNode = function(size) {
var crypto = require('crypto');
return crypto.randomBytes(size);
}
};
Random.getRandomBufferBrowser = function(size) {
if (!window.crypto && !window.msCrypto)
@ -38,11 +38,12 @@ Random.getRandomBufferBrowser = function(size) {
Random.getPseudoRandomBuffer = function(size) {
var b32 = 0x100000000;
var b = new Buffer(size);
var r;
for (var i = 0; i <= size; i++) {
var j = Math.floor(i / 4);
var k = i - j * 4;
if (k == 0) {
if (k === 0) {
r = Math.random() * b32;
b[i] = r & 0xff;
} else {

7
test/crypto/random.js

@ -1,5 +1,8 @@
'use strict';
var should = require('chai').should();
var Random = require('../lib/random');
var bitcore = require('../..');
var Random = bitcore.Random;
describe('Random', function() {
@ -21,7 +24,7 @@ describe('Random', function() {
var hexs = [];
for (var i = 0; i < 100; i++)
hexs[i] = Random.getRandomBuffer(8).toString('hex');
for (var i = 0; i < 100; i++)
for (i = 0; i < 100; i++)
for (var j = i + 1; j < 100; j++)
hexs[i].should.not.equal(hexs[j]);
});

Loading…
Cancel
Save