Files
test-repo/scripts/build/shims/crypto-random-fill-sync.cjs
T
2026-06-23 08:44:23 +08:00

26 lines
604 B
JavaScript

"use strict";
// eslint-disable-next-line no-redeclare
const { crypto } = globalThis;
if (crypto && typeof crypto.getRandomValues === "function") {
module.exports = {
randomFillSync(view) {
crypto.getRandomValues(view);
return view;
},
};
}
let state = 0x9e3779b9;
module.exports = {
randomFillSync(view) {
for (let index = 0; index < view.length; index++) {
state = Math.imul(state ^ (state >>> 15), state | 1);
state ^= state + Math.imul(state ^ (state >>> 7), state | 61);
view[index] = (state ^ (state >>> 14)) & 255;
}
return view;
},
};