温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/node/crypto/randomInt
点击访问原文链接

Node crypto.randomInt function | API Reference | Bun

Node crypto.randomInt function | API Reference | BunBuildDocsReferenceGuidesBlogDiscord/node:crypto/randomIntFrandomInt

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/node:crypto/randomIntFrandomInt

function

crypto.randomInt { if (err) throw err; console.log(`Random number chosen from (0, 1, 2): ${n}`); }); ``` ```js // Synchronous const { randomInt, } = await import('node:crypto'); const n = randomInt(3); console.log(`Random number chosen from (0, 1, 2): ${n}`); ``` ```js // With `min` argument const { randomInt, } = await import('node:crypto'); const n = randomInt(1, 7); console.log(`The dice rolled: ${n}`); ```" data-algolia-static="false" data-algolia-merged="false" data-type="Function">function randomInt(max: number): number;

Return a random integer n such that min . This implementation avoids modulo bias.

The range (max - min) must be less than 2**48. min and max must be safe integers.

If the callback function is not provided, the random integer is generated synchronously.

// Asynchronous
const {
randomInt,
} = await import('node:crypto');

randomInt(3, (err, n) => {
if (err) throw err;
console.log(`Random number chosen from (0, 1, 2): ${n}`);
});
// Synchronous
const {
randomInt,
} = await import('node:crypto');

const n = randomInt(3);
console.log(`Random number chosen from (0, 1, 2): ${n}`);
// With `min` argument
const {
randomInt,
} = await import('node:crypto');

const n = randomInt(1, 7);
console.log(`The dice rolled: ${n}`);
@param max

End of random range (exclusive).

function randomInt(min: number,max: number): number;

Return a random integer n such that min . This implementation avoids modulo bias.

The range (max - min) must be less than 2**48. min and max must be safe integers.

If the callback function is not provided, the random integer is generated synchronously.

// Asynchronous
const {
randomInt,
} = await import('node:crypto');

randomInt(3, (err, n) => {
if (err) throw err;
console.log(`Random number chosen from (0, 1, 2): ${n}`);
});
// Synchronous
const {
randomInt,
} = await import('node:crypto');

const n = randomInt(3);
console.log(`Random number chosen from (0, 1, 2): ${n}`);
// With `min` argument
const {
randomInt,
} = await import('node:crypto');

const n = randomInt(1, 7);
console.log(`The dice rolled: ${n}`);
@param min

Start of random range (inclusive).

@param max

End of random range (exclusive).

function randomInt(max: number,callback: (err: null | Error, value: number) => void): void;

Return a random integer n such that min . This implementation avoids modulo bias.

The range (max - min) must be less than 2**48. min and max must be safe integers.

If the callback function is not provided, the random integer is generated synchronously.

// Asynchronous
const {
randomInt,
} = await import('node:crypto');

randomInt(3, (err, n) => {
if (err) throw err;
console.log(`Random number chosen from (0, 1, 2): ${n}`);
});
// Synchronous
const {
randomInt,
} = await import('node:crypto');

const n = randomInt(3);
console.log(`Random number chosen from (0, 1, 2): ${n}`);
// With `min` argument
const {
randomInt,
} = await import('node:crypto');

const n = randomInt(1, 7);
console.log(`The dice rolled: ${n}`);
@param max

End of random range (exclusive).

@param callback

function(err, n) {}.

function randomInt(min: number,max: number,callback: (err: null | Error, value: number) => void): void;

Return a random integer n such that min . This implementation avoids modulo bias.

The range (max - min) must be less than 2**48. min and max must be safe integers.

If the callback function is not provided, the random integer is generated synchronously.

// Asynchronous
const {
randomInt,
} = await import('node:crypto');

randomInt(3, (err, n) => {
if (err) throw err;
console.log(`Random number chosen from (0, 1, 2): ${n}`);
});
// Synchronous
const {
randomInt,
} = await import('node:crypto');

const n = randomInt(3);
console.log(`Random number chosen from (0, 1, 2): ${n}`);
// With `min` argument
const {
randomInt,
} = await import('node:crypto');

const n = randomInt(1, 7);
console.log(`The dice rolled: ${n}`);
@param min

Start of random range (inclusive).

@param max

End of random range (exclusive).

@param callback

function(err, n) {}.

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

Node crypto.randomInt function | API Reference | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    API documentation for function node:crypto.randomInt | Bun