MCPcopy Index your code
hub / github.com/nodejs/node / randomBytes

Function randomBytes

lib/internal/crypto/random.js:100–118  ·  view source on GitHub ↗
(size, callback)

Source from the content-addressed store, hash-verified

98}
99
100function randomBytes(size, callback) {
101 size = assertSize(size, 1, 0, Infinity);
102 if (callback !== undefined) {
103 validateFunction(callback, 'callback');
104 }
105
106 const buf = new FastBuffer(size);
107
108 if (callback === undefined) {
109 randomFillSync(TypedArrayPrototypeGetBuffer(buf), 0, size);
110 return buf;
111 }
112
113 // Keep the callback as a regular function so this is propagated.
114 randomFill(TypedArrayPrototypeGetBuffer(buf), 0, size, function(error) {
115 if (error) return FunctionPrototypeCall(callback, this, error);
116 FunctionPrototypeCall(callback, this, null, buf);
117 });
118}
119
120function randomFillSync(buf, offset = 0, size) {
121 if (!isAnyArrayBuffer(buf) && !isArrayBufferView(buf)) {

Calls 3

randomFillSyncFunction · 0.85
randomFillFunction · 0.85
assertSizeFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…