本文整理汇总了TypeScript中underscore.random函数的典型用法代码示例。如果您正苦于以下问题:TypeScript random函数的具体用法?TypeScript random怎么用?TypeScript random使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了random函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getRandomCell
/**
* @param {Cell[]} exclude
* @returns {Cell}
*/
getRandomCell(exclude?:Cell[]):Cell {
const cells:Cell[] = this.getCells(exclude);
if (0 === cells.length) {
throw new Error('There are no cells available');
}
return cells[_.random(cells.length - 1)];
}
示例2: getRandomPredictions
// get a random train prediction and send them to websockets
async function getRandomPredictions(ws) {
let min = 1460592000
let max = Math.floor(Date.now() / 1000)
let ts = _.random(min, max)
let hash = await trainHashAtTimestamp(ts)
if (_.isEmpty(hash)) {
getRandomPredictions(ws);
} else {
let trains = await getTrainByHash(hash)
ws.send(JSON.stringify(trains[0]))
let timestamp = ts++
iterating = true
iterate(ws, timestamp)
}
}
示例3:
decide<T>(decision: Decision<T>) : Promise<T[]> {
const count = _.random(decision.minSelections, decision.maxSelections);
const picked = _.sample<T>(decision.options, count);
return Promise.resolve(picked);
}
示例4: pickRandomIndex
export function pickRandomIndex(list: any[]): number {
return _.random(list.length - 1);
}
示例5: getRandomStack
public getRandomStack(min?: number, max?: number): number {
return _.random(min || 1, max || 1);
}
示例6: doesChanceWork
export function doesChanceWork(chance: number): boolean {
let rand = _.random(CHANCE_PRECISE);
let rolled = rand * 100 / CHANCE_PRECISE;
return chance >= rolled;
}