• buffer {Buffer|TypedArray|DataView} Must be supplied.
    • offset {number} Default: 0
    • size {number} Default: buffer.length - offset
    • Returns: {Buffer|TypedArray|DataView} The object passed as buffer argument.

    Synchronous version of [crypto.randomFill()][].

    1. const buf = Buffer.alloc(10);
    2. console.log(crypto.randomFillSync(buf).toString('hex'));
    3. crypto.randomFillSync(buf, 5);
    4. console.log(buf.toString('hex'));
    5. // The above is equivalent to the following:
    6. crypto.randomFillSync(buf, 5, 5);
    7. console.log(buf.toString('hex'));

    Any TypedArray or DataView instance may be passed as buffer.

    1. const a = new Uint32Array(10);
    2. console.log(Buffer.from(crypto.randomFillSync(a).buffer,
    3. a.byteOffset, a.byteLength).toString('hex'));
    4. const b = new Float64Array(10);
    5. console.log(Buffer.from(crypto.randomFillSync(b).buffer,
    6. b.byteOffset, b.byteLength).toString('hex'));
    7. const c = new DataView(new ArrayBuffer(10));
    8. console.log(Buffer.from(crypto.randomFillSync(c).buffer,
    9. c.byteOffset, c.byteLength).toString('hex'));