• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript random-js.engines类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中random-js.engines的典型用法代码示例。如果您正苦于以下问题:TypeScript engines类的具体用法?TypeScript engines怎么用?TypeScript engines使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了engines类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: generateRandomNumberAndDisplay

	function generateRandomNumberAndDisplay() {
		var minNum = minimumNumber < maximumNumber ? minimumNumber : maximumNumber;
		var maxNum = minimumNumber > maximumNumber ? minimumNumber : maximumNumber;
		random = random || new Random(Random.engines.mt19937().autoSeed());
		var value = random.integer(minNum, maxNum);
		displayResult(value.toString());
	}
开发者ID:tkorcak,项目名称:createidsvscode,代码行数:7,代码来源:extension.ts


示例2: constructor

 constructor(config: RandomConfig) {
     this.engine = randomjs.engines.mt19937();
     if (typeof config.seed != 'undefined')
         this.engine.seed(config.seed);
     else
         this.engine.autoSeed();
 }
开发者ID:sbj42,项目名称:sbj42.github.io,代码行数:7,代码来源:random.ts


示例3: Date

/**
 * Options specifies arguments to the checker.
 *
 * @property tests The max number of tests
 * @property engine A random-js engine
 */
export interface CheckOptions {
  tests: number;
  engine: Random.MT19937;
  seed: number,
  locale: string;
  format: boolean
}

/**
 * Create default random engine.
 */
const seed = process.env.SEED || new Date().getTime();
const engine = Random.engines.mt19937()
engine.seed(seed);

/**
 * The default check options.
 */
export const stdOpts: CheckOptions = {
  tests : 50,
  engine : engine,
  seed: seed,
  locale : 'en',
  format: true
};
开发者ID:hychen,项目名称:hycheck,代码行数:31,代码来源:constants.ts


示例4: integer

import * as Random from "random-js";

const engine = Random.engines.mt19937().autoSeed();

/**
 * Randomly generate an integer, within the inclusive bounds.
 * @param min The smallest possible integer.
 * @param max The largest possible integer.
 */
export function integer(min: number, max: number): number {
    return Random.integer(min, max)(engine);
}

/**
 * Return a random boolean value
 */
export function bool(): boolean;
/**
 * Return a random boolean value with a percentage change of truth
 * @param percentage 0-1
 */
// tslint:disable-next-line:unified-signatures
export function bool(percentage: number): boolean;
/**
 * Return a random value that is true numerator times out of denominator
 */
export function bool(numerator?: number, denominator?: number): boolean {
    // any below because of bad TS definitions in the @types package.
    return Random.bool(numerator as any, denominator as any)(engine);
}
开发者ID:MPennanti,项目名称:HungryDragon,代码行数:30,代码来源:random.ts


示例5: Random

import { Define } from './define';
import * as Random from 'random-js';

export module Util {
    export let rand: Random = new Random(Random.engines.mt19937().autoSeed());

    export function dealTegomas(): string[] {
        let komaCircle = Define.komaCircle.split('');
        shuffle(komaCircle);
        let tegomas = new Array<string>();
        for (let c of cut(komaCircle, 8)) {
            tegomas.push(c.join(''));
        }
        return tegomas;
    }

    export function cut<T>(array: Array<T>, len: number): Array<Array<T>> {
        let ret = new Array<Array<T>>();
        const cutCount = array.length / len;
        for (let i = 0; i < cutCount; i = (i+1)|0) {
            ret.push(array.slice(i * len, (i + 1) * len));
        }
        return ret;
    }

    /** shuffle array - with Fisher-Yates algorithm */
    export function shuffle<T>(array: Array<T>) {
        let n = array.length;
        for (let i = n - 1; i > 0; i=i-1) {
            let j = rand.integer(0, i);
            let tmp = array[i];
开发者ID:Goita,项目名称:goita-core-js,代码行数:31,代码来源:util.ts


示例6: generateEntitiesForScenario

function generateEntitiesForScenario(
  input: Input,
  checkFitness: FitnessFunction,
  actor: string,
  initialPopulation: Entity[],
  seed: number
): EntityWithFitness[] {
  const populationSize = 256;
  const maxGenerations = 10;

  let generation = 0;

  const bestSolutions: BestEntities = { [actor]: [] };

  const random = new Random(Random.engines.mt19937().seed(seed));

  let population: Entity[] = [];

  while (generation < maxGenerations) {
    if (population.length < populationSize) {
      population.push(
        ...generateEntities(
          random,
          populationSize - population.length,
          input.keys
        )
      );
    }

    population.push(...initialPopulation);

    const populationWithFitnesses = population.map(entity =>
      checkFitness(input, entity, actor)
    );

    const populationSortedByFitness = populationWithFitnesses.sort(
      (a, b) => a.fitness - b.fitness
    );

    if (populationSortedByFitness[0].fitness < 20) {
      console.log("early return!", populationSortedByFitness[0].fitness / 1000);
      return populationSortedByFitness.slice(0, 10);
    }

    bestSolutions[actor] = bestSolutions[actor]
      .concat(populationSortedByFitness)
      .sort((a, b) => a.fitness - b.fitness)
      .slice(0, 100);

    console.log(
      generation,
      (bestSolutions[actor][0] || { fitness: Infinity }).fitness / 1000
    );

    const children = breed(
      populationSortedByFitness
        .slice(0, 32)
        .concat(bestSolutions[actor].slice(0, 8)),
      populationSize / 2,
      random
    );

    while (population.length > 0) {
      population.pop();
    }

    population.push(...children);

    population = population.map(entity => mutate(input.keys, random, entity));

    generation += 1;
  }

  return bestSolutions[actor].slice(0, 10);
}
开发者ID:helix-pi,项目名称:helix-pi,代码行数:75,代码来源:index.ts


示例7: generateEntity

export function generateEntity(
  seed: number,
  keys: string[],
  depth = 0
): Entity {
  const random = new Random(Random.engines.mt19937().seed(seed));

  const isLeaf = depth > 1 || random.bool();

  if (isLeaf) {
    const possibleCommands = [
      "move",
      "setVelocity",
      "multiplyVelocity",
      "noop"
    ];

    const command = random.pick(possibleCommands);

    if (command === "noop") {
      return {
        type: command,
        id: seed.toString()
      };
    }

    if (command === "move") {
      const direction = random.pick([
        "up",
        "right",
        "left",
        "down"
      ]) as Direction;
      const amount = random.integer(0, 20) / 10;

      return {
        type: command,
        id: seed.toString(),
        direction,
        amount
      };
    }

    if (command === "setVelocity") {
      let velocity;

      if (random.bool(0.5)) {
        // cardinal direction
        const scalar = random.integer(0, 20) / 20;

        velocity = random.pick([
          { x: 0, y: -scalar },
          { x: scalar, y: 0 },
          { x: -scalar, y: 0 },
          { x: 0, y: scalar }
        ]);
      } else {
        velocity = {
          x: random.integer(-20, 20) / 20,
          y: random.integer(-20, 20) / 20
        };
      }

      return {
        type: command,
        id: seed.toString(),
        velocity
      };
    }

    if (command === "multiplyVelocity") {
      const scalar = random.integer(-20, 20) / 20;

      return {
        type: command,
        id: seed.toString(),
        scalar
      };
    }

    throw new Error("Unimplemented command");
  } else {
    const possibleCommands = [
      "sequence",
      "inputConditional",
      "collisionConditional"
    ];

    if (depth === 0) {
      possibleCommands.push("onCreate");
    }
    // TODO - fix definitely typed definition
    const command = (random as any).pick(possibleCommands) as any;

    if (command === "collisionConditional") {
      return {
        type: command,
        id: seed.toString(),
        children: makeChildren(random, 1, keys, depth)
      };
//.........这里部分代码省略.........
开发者ID:helix-pi,项目名称:helix-pi,代码行数:101,代码来源:index.ts


示例8: makeFitnessChecker

  Object.keys(input.actors).forEach(actor => {
    const scenariosForActor = input.scenarios.filter(
      scenario => actor in scenario.actors
    );

    if (scenariosForActor.length === 1) {
      console.log("Generating for", actor);
      const scenario = scenariosForActor[0];

      if (!(actor in scenario.actors)) {
        return;
      }

      const fitness = makeFitnessChecker([scenario]);
      let previousSolutions: Entity[] = [];

      if (previousOutput && previousOutput.entities[actor]) {
        previousSolutions = [previousOutput.entities[actor]];
      }

      const bestSolutions = generateEntitiesForScenario(
        input,
        fitness,
        actor,
        previousSolutions,
        seed
      );

      console.log("size before tumbler", findSize(bestSolutions[0].entity));
      results.entities[actor] = tumbler(
        bestSolutions[0].entity,
        [scenario],
        input,
        actor
      );
      console.log("size after tumbler", findSize(results.entities[actor]));

      setErrorLevel(results.errorLevels, actor, {
        [scenario.id]: bestSolutions[0].fitness
      });
      results.positions[actor] = bestSolutions[0].positions;
    } else {
      console.log("Generating for", actor);
      const random = new Random(Random.engines.mt19937().seed(seed));

      let previousSolutions: Entity[] = [];

      if (previousOutput && previousOutput.entities[actor]) {
        previousSolutions = [previousOutput.entities[actor]];
      }

      const entitiesForEachScenario = flatten(
        scenariosForActor.map(
          scenario =>
            console.log("scenario:", scenario.name) ||
            generateEntitiesForScenario(
              input,
              makeFitnessChecker([scenario]),
              actor,
              previousSolutions,
              random.integer((-2) ** 53, 2 ** 53)
            )
        )
      );

      console.log("final solution:", previousSolutions, previousOutput);
      const solutions = generateEntitiesForScenario(
        input,
        makeFitnessChecker(scenariosForActor),
        actor,
        previousSolutions.concat(
          entitiesForEachScenario.map(
            entityWithFitness => entityWithFitness.entity
          )
        ),
        random.integer((-2) ** 53, 2 ** 53)
      );

      console.log("size before tumbler", findSize(solutions[0].entity));
      results.entities[actor] = tumbler(
        solutions[0].entity,
        scenariosForActor,
        input,
        actor
      );
      console.log("size after tumbler", findSize(results.entities[actor]));
      setErrorLevel(results.errorLevels, actor, solutions[0].errorLevels);
      results.positions[actor] = solutions[0].positions;
    }
  });
开发者ID:helix-pi,项目名称:helix-pi,代码行数:90,代码来源:index.ts


示例9: chooseMutation

function chooseMutation(
  keys: string[],
  seed: number,
  entity: Entity
): Mutation {
  const random = new Random(Random.engines.mt19937().seed(seed));

  if (random.bool(0.5)) {
    return {
      id: seed.toString(),
      type: "ConvertToNoopMutation"
    };
  }

  if (entity.type === "sequence") {
    const types = [
      "NewEntityMutation",
      "RemovalMutation",
      "SwitchMutation",
      "ReplaceMutation"
    ];

    const mutationType = random.pick(types);

    if (mutationType === "NewEntityMutation") {
      const newEntity = generateEntity(
        random.integer(MIN_SEED, MAX_SEED),
        keys,
        0
      );

      return {
        id: seed.toString(),
        type: mutationType,
        newEntity,
        spliceIndex: random.integer(0, (entity as Branch).children.length)
      };
    }

    if (mutationType === "ReplaceMutation") {
      const newEntity = generateEntity(
        random.integer(MIN_SEED, MAX_SEED),
        keys,
        0
      );

      return {
        id: seed.toString(),
        type: mutationType,
        newEntity,
        spliceIndex: random.integer(0, (entity as Branch).children.length - 1)
      };
    }

    if (mutationType === "RemovalMutation") {
      return {
        id: seed.toString(),
        type: mutationType,
        removeIndex: random.integer(0, entity.children.length - 1)
      };
    }

    if (mutationType === "SwitchMutation") {
      return {
        id: seed.toString(),
        type: mutationType,
        fromIndex: random.integer(0, entity.children.length - 1),
        toIndex: random.integer(0, entity.children.length - 1)
      };
    }
  }

  if (entity.type === "onCreate") {
    const newEntity = generateEntity(
      random.integer(MIN_SEED, MAX_SEED),
      keys,
      0
    );

    return {
      id: seed.toString(),
      type: "ReplaceMutation",
      newEntity,
      spliceIndex: random.pick([0, 1])
    };
  }

  if (entity.type === "collisionConditional") {
    const newEntity = generateEntity(
      random.integer(MIN_SEED, MAX_SEED),
      keys,
      0
    );

    return {
      id: seed.toString(),
      type: "ReplaceMutation",
      newEntity,
      spliceIndex: random.pick([0, 1])
    };
//.........这里部分代码省略.........
开发者ID:helix-pi,项目名称:helix-pi,代码行数:101,代码来源:index.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript randomstring.generate函数代码示例发布时间:2022-05-25
下一篇:
TypeScript random-js.pick函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap