lotus-sdk
Version:
Central repository for several classes of tools for integrating with, and building for, the Lotusia ecosystem
31 lines (30 loc) • 862 B
JavaScript
import { randomBytes as nobleRandomBytes } from '@noble/hashes/utils';
export class Random {
static getRandomBuffer(size) {
return Buffer.from(nobleRandomBytes(size));
}
static getRandomBufferNode(size) {
return Random.getRandomBuffer(size);
}
static getRandomBufferBrowser(size) {
return Random.getRandomBuffer(size);
}
static getPseudoRandomBuffer(size) {
const b32 = 0x100000000;
const b = Buffer.alloc(size);
let r = 0;
for (let i = 0; i <= size; i++) {
const j = Math.floor(i / 4);
const k = i - j * 4;
if (k === 0) {
r = Math.random() * b32;
b[i] = r & 0xff;
}
else {
r = r >>> 8;
b[i] = r & 0xff;
}
}
return b;
}
}