Код IT
← Каталог

Рандомизация — JavaScript (Node.js)

Math.random() для обычной логики и crypto.randomBytes для безопасных значений.

javascript labexperimentsrandomnodejs embed URL статья в энциклопедии
JavaScript main.js
import crypto from "node:crypto";

const pseudo = Math.random();               // PRNG движка
const secure = crypto.randomBytes(16);      // CSPRNG

console.log(pseudo, secure.toString("hex"));
import crypto from "node:crypto";

const pseudo = Math.random();               // PRNG движка
const secure = crypto.randomBytes(16);      // CSPRNG

console.log(pseudo, secure.toString("hex"));