get_random_number
Generate random integers within a specified range for applications requiring unpredictable values, such as simulations, games, or data sampling.
Instructions
지정한 범위 내에서 랜덤 정수를 생성합니다.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| min | Yes | 최소값 (정수) | |
| max | Yes | 최대값 (정수) | |
| count | No | 생성할 숫자 개수 (1-10). 기본값: 1 |
Implementation Reference
- src/index.ts:179-208 (handler)The MCP tool handler function that receives validated inputs, calls the core generateRandomNumbers helper, handles errors, and returns formatted text response.async ({ min, max, count }) => { const result = generateRandomNumbers(min, max, count || 1); if (result.isError) { return { content: [ { type: "text", text: result.errorMessage!, }, ], isError: true, }; } const n = result.numbers.length; const resultText = n === 1 ? `랜덤 숫자 (${result.min}~${result.max}): ${result.numbers[0]}` : `랜덤 숫자 ${n}개 (${result.min}~${result.max}): ${result.numbers.join(", ")}`; return { content: [ { type: "text", text: resultText, }, ], }; }
- src/tools.ts:106-133 (helper)Core pure function generateRandomNumbers that implements the random number generation logic using Math.random(). Validates min <= max, generates up to 10 random integers inclusive.export function generateRandomNumbers( min: number, max: number, count: number = 1 ): RandomResult { if (min > max) { return { numbers: [], min, max, isError: true, errorMessage: "오류: 최소값이 최대값보다 큽니다.", }; } const numbers: number[] = []; for (let i = 0; i < count; i++) { const randomNum = Math.floor(Math.random() * (max - min + 1)) + min; numbers.push(randomNum); } return { numbers, min, max, isError: false, }; }
- src/index.ts:168-178 (schema)Zod schema for tool parameters: min (int), max (int), count (int 1-10 optional).{ min: z.number().int().describe("최소값 (정수)"), max: z.number().int().describe("최대값 (정수)"), count: z .number() .int() .min(1) .max(10) .optional() .describe("생성할 숫자 개수 (1-10). 기본값: 1"), },
- src/index.ts:165-209 (registration)server.tool call that registers 'get_random_number' with name, description, input schema, and handler function.server.tool( "get_random_number", "지정한 범위 내에서 랜덤 정수를 생성합니다.", { min: z.number().int().describe("최소값 (정수)"), max: z.number().int().describe("최대값 (정수)"), count: z .number() .int() .min(1) .max(10) .optional() .describe("생성할 숫자 개수 (1-10). 기본값: 1"), }, async ({ min, max, count }) => { const result = generateRandomNumbers(min, max, count || 1); if (result.isError) { return { content: [ { type: "text", text: result.errorMessage!, }, ], isError: true, }; } const n = result.numbers.length; const resultText = n === 1 ? `랜덤 숫자 (${result.min}~${result.max}): ${result.numbers[0]}` : `랜덤 숫자 ${n}개 (${result.min}~${result.max}): ${result.numbers.join(", ")}`; return { content: [ { type: "text", text: resultText, }, ], }; } );
- src/tools.ts:98-104 (schema)TypeScript interface defining the return type RandomResult for the helper function.export interface RandomResult { numbers: number[]; min: number; max: number; isError: boolean; errorMessage?: string; }