本文整理汇总了TypeScript中lodash.random函数的典型用法代码示例。如果您正苦于以下问题:TypeScript random函数的具体用法?TypeScript random怎么用?TypeScript random使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了random函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: addRandomObstacles
public addRandomObstacles(count: number) {
// apply some magic to count free cells
let freeCells = this.map.cells.reduce(
(prev, curr) => {
if (curr.isBlockable) {
prev++;
}
return prev;
}, 0);
if (count > freeCells) {
count = freeCells;
}
for (let i = 0; i < count; i++) {
let row = _.random(0, this.map.rows - 1);
let col = _.random(0, this.map.cols - 1);
if (this.map.grid[row][col].isBlockable) {
this.map.grid[row][col].type = CellType.Blocked;
// this.map.hasChanged(this.map.grid[row][col]);
} else {
i--;
}
}
}
示例2: value
function value () {
switch (random(0, 1)) {
case 0:
return random(0, 1) ? 'ON' : 'OFF';
case 1:
return random(1000, 9000) * 0.001;
}
}
示例3: getRandomPosition
private getRandomPosition() {
let y: number;
let x: number;
do {
y = _.random(0, this.map.rows - 1);
x = _.random(0, this.map.cols - 1);
} while (!this.isPositionFree(x, y));
return new Position(x, y);
}
示例4: update
public update() {
for (let robot of this.robots) {
let y: number;
let x: number;
do {
y = robot.position.y + _.random(-1, 1);
x = robot.position.x + _.random(-1, 1);
} while (!this.isPositionFree(x, y));
robot.currentCell.color = undefined;
robot.moveTo(new Position(x, y));
robot.currentCell.color = "#BBF";
}
}
示例5: update
update (level: GameLevel): void {
if (!this.actionQueue.length) {
var actionCount: number = _.random(1, 4)
for (var i = 0 ; i < actionCount ; i++) {
this.queueActions(
new MoveInDirectionAction(Direction.getRandom(), _.random(1, 3), 1),
)
}
this.queueActions(new WaitAction(_.random(4000)))
}
super.update(level)
}
示例6: test
test('queues a reattempt if the task fails', async () => {
const initialAttempts = _.random(0, 2);
const id = Date.now().toString();
const { runner, store } = testOpts({
instance: {
id,
attempts: initialAttempts,
params: { a: 'b' },
state: { hey: 'there' },
},
definitions: {
testtype: {
createTaskRunner: () => ({
async run() {
throw new Error('Dangit!');
},
}),
},
},
});
await runner.run();
sinon.assert.calledOnce(store.update);
const instance = store.update.args[0][0];
expect(instance.id).toEqual(id);
expect(instance.attempts).toEqual(initialAttempts + 1);
expect(instance.runAt.getTime()).toBeGreaterThan(Date.now());
expect(instance.params).toEqual({ a: 'b' });
expect(instance.state).toEqual({ hey: 'there' });
});
示例7:
extraOutputs.forEach(function(output) {
output.script = bitcoin.address.toOutputScript(output.address, bitcoin.getNetwork());
// decide where to put the outputs - default is to randomize unless forced to end
const outputIndex = params.forceChangeAtEnd ? outputs.length : _.random(0, outputs.length);
outputs.splice(outputIndex, 0, output);
});
示例8: enabler
"!typegame": enabler((command: Tennu.Command) => {
var cache = typegameCache[command.channel] = typegameCache[command.channel] || { running: false };
if (typegameCache[command.channel].running) {
return util.format("A game is still running! Name %s PokĂŠmon with the type %s!", cache.cnt, cache.types.join("/"));
} else {
(runningCache[command.channel] = runningCache[command.channel] || []).push("typegame")
var {type, cnt} = _.sample(Data.type_count_array);
console.log(cnt);
cache = typegameCache[command.channel] = {
running: true,
type: type,
cnt: _.random(1, _.min([5, cnt])),
max: cnt,
userCount: {},
guessed: {},
types: []
};
for (var i = 0; type; type >>= 1, ++i) {
if (type&1)
cache.types.push(Data.type_list[i]);
}
return util.format("Name %s PokĂŠmon with the type %s!",
cache.cnt, cache.types.join("/")
);
}
}),
示例9: times
return times(8 , (index) => {
return {
id: index,
type: random (0, 1) === 1 ? 'input' : 'output',
value: value()
};
});
示例10:
_.times(pointsLength, (i) => {
points[0].push([
i,
_.random(0, height)
]);
points[1].push([
i,
_.random(0, height)
]);
points[2].push([
i,
_.random(0, height)
]);
});