当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript lodash.random函数代码示例

本文整理汇总了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--;
            }
        }
    }
开发者ID:oliverguhr,项目名称:pathsim,代码行数:25,代码来源:ObstacleGenerator.ts

示例2: value

 function value () {
     switch (random(0, 1)) {
         case 0:
             return random(0, 1) ? 'ON' : 'OFF';
         case 1:
             return random(1000, 9000) * 0.001;
     }
 }
开发者ID:syafiqrokman,项目名称:angular5-iot-dashboard,代码行数:8,代码来源:mocks.service.ts

示例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);
    }
开发者ID:oliverguhr,项目名称:pathsim,代码行数:10,代码来源:DynmicObstacleGenerator.ts

示例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";
     }
 }
开发者ID:oliverguhr,项目名称:pathsim,代码行数:13,代码来源:DynmicObstacleGenerator.ts

示例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)
	}
开发者ID:bteixeira,项目名称:phaser-tryouts,代码行数:14,代码来源:wanderer-personality.ts

示例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' });
  });
开发者ID:liuyepiaoxiang,项目名称:kibana,代码行数:32,代码来源:task_runner.test.ts

示例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);
      });
开发者ID:BitGo,项目名称:BitGoJS,代码行数:7,代码来源:transactionBuilder.ts

示例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("/")
         );
     }
 }),
开发者ID:Cu3PO42,项目名称:CuBoid,代码行数:26,代码来源:typegame.ts

示例9: times

 return times(8 , (index) => {
     return {
         id: index,
         type: random (0, 1) === 1 ? 'input' : 'output',
         value: value()
     };
 });
开发者ID:syafiqrokman,项目名称:angular5-iot-dashboard,代码行数:7,代码来源:mocks.service.ts

示例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)
	]);
});
开发者ID:egorovsa,项目名称:simple-2D-gl,代码行数:16,代码来源:app.ts


注:本文中的lodash.random函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。