Skip to content
Discussion options

You must be logged in to vote

Replacing Math.random() with secure methods like crypto.getRandomValues or crypto.randomBytes provides much-needed randomness integrity for applications requiring secure data handling. Use these replacements whenever the predictability of Math.random() could pose a risk.

function getSecureRandomValue(max) {
const array = new Uint32Array(1);
window.crypto.getRandomValues(array);
return (array[0] / (0xffffffff + 1)) * max;
}

function tint() {
image.tint = getSecureRandomValue(0xFFFFFF);
}

function changeTint() {
pic.tint = getSecureRandomValue(0xffffff);
}

const crypto = require('crypto');

function getSecureRandomValue(max) {
return parseInt(crypto.randomBytes(4).toString('hex'), 16) / 0xFF…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by akaday
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Show & Tell Discussions where community members share their projects, experiments, or accomplishments
2 participants