| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6c9b19a commit f46d293
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4454,16 +4454,12 @@ const a = new Uint32Array(10); | |||
| 4454 | 4454 | console.log(Buffer.from(randomFillSync(a).buffer, | |
| 4455 | 4455 | a.byteOffset, a.byteLength).toString('hex')); | |
| 4456 | 4456 | ||
| 4457 | - const b = new Float64Array(10); | ||
| 4457 | + const b = new DataView(new ArrayBuffer(10)); | ||
| 4458 | 4458 | console.log(Buffer.from(randomFillSync(b).buffer, | |
| 4459 | 4459 | b.byteOffset, b.byteLength).toString('hex')); | |
| 4460 | 4460 | ||
| 4461 | - const c = new DataView(new ArrayBuffer(10)); | ||
| 4462 | - console.log(Buffer.from(randomFillSync(c).buffer, | ||
| 4463 | - c.byteOffset, c.byteLength).toString('hex')); | ||
| 4464 | - | ||
| 4465 | - const d = new ArrayBuffer(10); | ||
| 4466 | - console.log(Buffer.from(randomFillSync(d)).toString('hex')); | ||
| 4461 | + const c = new ArrayBuffer(10); | ||
| 4462 | + console.log(Buffer.from(randomFillSync(c)).toString('hex')); | ||
| 4467 | 4463 | ``` | |
| 4468 | 4464 | ||
| 4469 | 4465 | ```cjs | |
@@ -4475,16 +4471,12 @@ const a = new Uint32Array(10); | |||
| 4475 | 4471 | console.log(Buffer.from(randomFillSync(a).buffer, | |
| 4476 | 4472 | a.byteOffset, a.byteLength).toString('hex')); | |
| 4477 | 4473 | ||
| 4478 | - const b = new Float64Array(10); | ||
| 4474 | + const b = new DataView(new ArrayBuffer(10)); | ||
| 4479 | 4475 | console.log(Buffer.from(randomFillSync(b).buffer, | |
| 4480 | 4476 | b.byteOffset, b.byteLength).toString('hex')); | |
| 4481 | 4477 | ||
| 4482 | - const c = new DataView(new ArrayBuffer(10)); | ||
| 4483 | - console.log(Buffer.from(randomFillSync(c).buffer, | ||
| 4484 | - c.byteOffset, c.byteLength).toString('hex')); | ||
| 4485 | - | ||
| 4486 | - const d = new ArrayBuffer(10); | ||
| 4487 | - console.log(Buffer.from(randomFillSync(d)).toString('hex')); | ||
| 4478 | + const c = new ArrayBuffer(10); | ||
| 4479 | + console.log(Buffer.from(randomFillSync(c)).toString('hex')); | ||
| 4488 | 4480 | ``` | |
| 4489 | 4481 | ||
| 4490 | 4482 | ### `crypto.randomFill(buffer[, offset][, size], callback)` | |
@@ -4560,6 +4552,12 @@ randomFill(buf, 5, 5, (err, buf) => { | |||
| 4560 | 4552 | Any `ArrayBuffer`, `TypedArray`, or `DataView` instance may be passed as | |
| 4561 | 4553 | `buffer`. | |
| 4562 | 4554 | ||
| 4555 | + While this includes instances of `Float32Array` and `Float64Array`, this | ||
| 4556 | + function should not be used to generate random floating-point numbers. The | ||
| 4557 | + result may contain `+Infinity`, `-Infinity`, and `NaN`, and even if the array | ||
| 4558 | + contains finite numbers only, they are not drawn from a uniform random | ||
| 4559 | + distribution and have no meaningful lower or upper bounds. | ||
| 4560 | + | ||
| 4563 | 4561 | ```mjs | |
| 4564 | 4562 | const { | |
| 4565 | 4563 | randomFill, | |
@@ -4572,22 +4570,15 @@ randomFill(a, (err, buf) => { | |||
| 4572 | 4570 | .toString('hex')); | |
| 4573 | 4571 | }); | |
| 4574 | 4572 | ||
| 4575 | - const b = new Float64Array(10); | ||
| 4573 | + const b = new DataView(new ArrayBuffer(10)); | ||
| 4576 | 4574 | randomFill(b, (err, buf) => { | |
| 4577 | 4575 | if (err) throw err; | |
| 4578 | 4576 | console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength) | |
| 4579 | 4577 | .toString('hex')); | |
| 4580 | 4578 | }); | |
| 4581 | 4579 | ||
| 4582 | - const c = new DataView(new ArrayBuffer(10)); | ||
| 4580 | + const c = new ArrayBuffer(10); | ||
| 4583 | 4581 | randomFill(c, (err, buf) => { | |
| 4584 | - if (err) throw err; | ||
| 4585 | - console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength) | ||
| 4586 | - .toString('hex')); | ||
| 4587 | - }); | ||
| 4588 | - | ||
| 4589 | - const d = new ArrayBuffer(10); | ||
| 4590 | - randomFill(d, (err, buf) => { | ||
| 4591 | 4582 | if (err) throw err; | |
| 4592 | 4583 | console.log(Buffer.from(buf).toString('hex')); | |
| 4593 | 4584 | }); | |
@@ -4605,22 +4596,15 @@ randomFill(a, (err, buf) => { | |||
| 4605 | 4596 | .toString('hex')); | |
| 4606 | 4597 | }); | |
| 4607 | 4598 | ||
| 4608 | - const b = new Float64Array(10); | ||
| 4599 | + const b = new DataView(new ArrayBuffer(10)); | ||
| 4609 | 4600 | randomFill(b, (err, buf) => { | |
| 4610 | 4601 | if (err) throw err; | |
| 4611 | 4602 | console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength) | |
| 4612 | 4603 | .toString('hex')); | |
| 4613 | 4604 | }); | |
| 4614 | 4605 | ||
| 4615 | - const c = new DataView(new ArrayBuffer(10)); | ||
| 4606 | + const c = new ArrayBuffer(10); | ||
| 4616 | 4607 | randomFill(c, (err, buf) => { | |
| 4617 | - if (err) throw err; | ||
| 4618 | - console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength) | ||
| 4619 | - .toString('hex')); | ||
| 4620 | - }); | ||
| 4621 | - | ||
| 4622 | - const d = new ArrayBuffer(10); | ||
| 4623 | - randomFill(d, (err, buf) => { | ||
| 4624 | 4608 | if (err) throw err; | |
| 4625 | 4609 | console.log(Buffer.from(buf).toString('hex')); | |
| 4626 | 4610 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments