當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。