本文整理匯總了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;
}