vendredi 9 février 2018

Nodejs generate secure random characters not including given chars

I was reading about generating secure random generator in nodejs. I tried this and works well to generate secure random characters.

const crypto = require('crypto');

var length = 22
var generated = crypto.randomBytes(Math.ceil(length / 2))
                      .toString('hex').slice(0, length);
//it returned "14cf777d3ca307f5e78496"

How can I generate secure random characters not including given pattern in nodejs. Ex: ['a', '2']




Aucun commentaire:

Enregistrer un commentaire