Skip to content

Instantly share code, notes, and snippets.

@carlok carlok/mRandom.js
Last active Mar 27, 2017

Embed
What would you like to do?
Random Bytes Node Module
// based on https://blog.tompawlak.org/generate-random-values-nodejs-javascript
const crypto = require('crypto');
function randomValueHex (len) {
return crypto.randomBytes(Math.ceil(len / 2))
.toString('hex') // convert to hexadecimal format
.slice(0, len); // return required number of characters
}
module.exports = {
randomValueHex: randomValueHex
};
/*
// usage:
const mRand = require('./mRandom.js');
console.log(mRand.randomValueHex(32));
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.