summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/internal/crypto/_randomInt.ts
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node/polyfills/internal/crypto/_randomInt.ts')
-rw-r--r--ext/node/polyfills/internal/crypto/_randomInt.ts11
1 files changed, 3 insertions, 8 deletions
diff --git a/ext/node/polyfills/internal/crypto/_randomInt.ts b/ext/node/polyfills/internal/crypto/_randomInt.ts
index 637251541..4e55eba9d 100644
--- a/ext/node/polyfills/internal/crypto/_randomInt.ts
+++ b/ext/node/polyfills/internal/crypto/_randomInt.ts
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+const ops = globalThis.Deno.core.ops;
+
export default function randomInt(max: number): number;
export default function randomInt(min: number, max: number): number;
export default function randomInt(
@@ -40,16 +42,9 @@ export default function randomInt(
throw new Error("Min is bigger than Max!");
}
- const randomBuffer = new Uint32Array(1);
-
- globalThis.crypto.getRandomValues(randomBuffer);
-
- const randomNumber = randomBuffer[0] / (0xffffffff + 1);
-
min = Math.ceil(min);
max = Math.floor(max);
-
- const result = Math.floor(randomNumber * (max - min)) + min;
+ const result = ops.op_node_random_int(min, max);
if (cb) {
cb(null, result);