简体   繁体   English

Typescript 导入模块 npm

[英]Typescript import module npm

I need to create a method called rollDice which uses the 'random' library to generate and return a random integer between 1 and 6. This is the code I have so far:我需要创建一个名为 rollDice 的方法,它使用“随机”库生成并返回 1 到 6 之间的随机 integer。这是我目前的代码:

import random from 'random'

function rollDice(min:number, max:number) {
    return Math.floor(Math.random() * (max - min + 1) + min)
}
 
let result = rollDice(1,6)
console.log(result)

I don't know how to call the 'random' thanks for helping!!我不知道如何称呼“随机”谢谢你的帮助!!

As described in the usage instructions for that module:如该模块的使用说明中所述:

int value = random.int((min = 1), (max = 6));

This returns a uniformly distributed integer in the 1 (inclusive) to 6 (inclusive) range.这将返回 1(含)到 6(含)范围内的均匀分布的 integer。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM