Update random.js

This commit is contained in:
wioniqle-q 2021-11-15 14:53:11 +03:00 committed by GitHub
commit ff39de1101
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,20 +1,22 @@
module.exports = class RandomKeyGenerator { module.exports = class RandomKeyGenerator {
// Initialize a new generator with the given keySpace // Initialize a new generator with the given keySpace
constructor(options = {}) { constructor(options = {}) {
this.keyspace = options.keyspace || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; this.keyspace = options.keyspace || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
}
// Generate a key of the given length
createKey(keyLength) {
var text = '';
for (var i = 0; i < keyLength; i++) {
const index = Math.floor(Math.random() * this.keyspace.length);
text += this.keyspace.charAt(index);
} }
return text; // Generate a key of the given length
} createKey(keyLength) {
let i;
let text;
text = '';
for (i = 0; i < keyLength; i++) {
const index = Math.floor(Math.random() * this.keyspace.length);
text += this.keyspace.charAt(index);
}
return text;
}
}; };