From 502eb30870920007995a57753b34affdd2ca1401 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Sat, 1 Jul 2023 13:02:13 +0200 Subject: [PATCH] removed prng module --- lib/prng.js | 29 ----------------------------- lib/rooms.js | 4 ++-- routes/site.js | 4 ++-- 3 files changed, 4 insertions(+), 33 deletions(-) delete mode 100644 lib/prng.js diff --git a/lib/prng.js b/lib/prng.js deleted file mode 100644 index ad3e774..0000000 --- a/lib/prng.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; - -const crypto = require('crypto'); - -const rrange = 4294967296; - -/** - * Return an integer, pseudo-random number in the range [0, 2^32). - */ - -const nextInt = function() { - return crypto.randomBytes(4).readUInt32BE(0); -}; - -/** - * Return a floating-point, pseudo-random number in the range [0, 1). - */ - -const rand = function() { - return nextInt() / rrange; -}; - -/** - * Return an integer, pseudo-random number in the range [0, max). - */ - -exports.randInt = function(max) { - return Math.floor(rand() * max); -}; diff --git a/lib/rooms.js b/lib/rooms.js index bd40488..865e519 100644 --- a/lib/rooms.js +++ b/lib/rooms.js @@ -3,7 +3,7 @@ const amatch = require('./match'); const clients = require('./redis-clients'); const config = require('../config'); -const randInt = require('./prng').randInt; +const randomInt = require('crypto').randomInt; const updateStats = require('./stats'); const utils = require('./utils'); @@ -513,7 +513,7 @@ Room.prototype.resetPoints = function(roundonly) { Room.prototype.sendLoadTrack = function() { this.status = Room.LOADING; - const index = randInt(this.trackscount); + const index = randomInt(this.trackscount); const room = this; songsdb.zrange(this.roomname, index, index, function(err, res) { diff --git a/routes/site.js b/routes/site.js index f1ce13b..4375291 100644 --- a/routes/site.js +++ b/routes/site.js @@ -5,7 +5,7 @@ const config = require('../config'); const db = require('../lib/redis-clients').songs; const http = require('http'); const parallel = require('async/parallel'); -const randInt = require('../lib/prng').randInt; +const randomInt = require('crypto').randomInt; const randomSlogan = require('../lib/utils').randomSlogan; const rooms = require('../lib/rooms').rooms; @@ -15,7 +15,7 @@ const rooms = require('../lib/rooms').rooms; const subTask = function(genre) { return function(callback) { - const index = randInt(rooms[genre].trackscount); + const index = randomInt(rooms[genre].trackscount); db.zrange(genre, index, index, function(err, res) { if (err) { return callback(err); -- 2.54.0