本文整理汇总了TypeScript中random-js.integer函数的典型用法代码示例。如果您正苦于以下问题:TypeScript integer函数的具体用法?TypeScript integer怎么用?TypeScript integer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了integer函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
return function (engine, locale) {
const n = integer(min, max)(engine);
return [...new Array(n).keys()].map(() => {
const chosenArb = arb ? arb : recursive(array, any, 2);
return chosenArb.makeGenerator()(engine, locale);
});
};
示例2: integer
integer(min: number | undefined, max: number | undefined): number {
if (!min)
min = 1;
if (!max)
max = min;
if (max < min)
throw new Error('minmax');
return randomjs.integer(min, max)(this.engine);
}
示例3: rec
function rec(n: number): Arbitrary<V, RecursiveGenOpts<V, O>> {
const chance = integer(0, 3)(engine);
if (n <= 0 || chance === 0) {
return n === depth ? combinator(arb) : arb;
}
else {
return combinator(rec(n - 1));
}
};
示例4:
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];
array[i] = array[j];
array[j] = tmp;
}
}
示例5: mutateNode
function mutateNode(keys: string[], random: Random, entity: Entity): Entity {
const willMutate = random.bool(MUTATE_PERCENTAGE);
if (!willMutate) {
return entity;
}
const mutationId = random.integer(MIN_SEED, MAX_SEED);
const mutation = chooseMutation(keys, mutationId, entity);
return applyMutation(entity, mutation);
}
示例6: generateEntities
function generateEntities(
random: Random,
generationSize: number,
keys: string[]
): Entity[] {
const entities = [];
while (entities.length < generationSize) {
entities.push(generateEntity(random.integer(MIN_SEED, MAX_SEED), keys));
}
return entities;
}
示例7: function
return function (engine, locale) {
function pick(n: number, [[k, x], ...xs]): any {
return (n <= k) ? x : pick(n - k, xs);
}
const total = sum(pool.map(e => e[0]));
const head = integer(1, total)(engine);
const result = pick(head, pool);
if (result instanceof Arbitrary) {
return result.makeGenerator()(engine, locale);
}
else {
return result;
};
};
示例8: integer
gen: (opts: { min: number }) => (engine) => integer(opts.min, 2)(engine),
示例9: integer
randexp.randInt = (from: number, to: number) => {
return integer(from, to)(engine);
}
示例10: integer
export function integer(min: number, max: number): number {
return Random.integer(min, max)(engine);
}