Skip to content

Instantly share code, notes, and snippets.



Last active Mar 27, 2017
What would you like to do?
Random Bytes Node Module
// based on
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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment