本文整理汇总了TypeScript中faker.random.number方法的典型用法代码示例。如果您正苦于以下问题:TypeScript random.number方法的具体用法?TypeScript random.number怎么用?TypeScript random.number使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类faker.random
的用法示例。
在下文中一共展示了random.number方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: modifyReplaceCapitalize
function modifyReplaceCapitalize(name: string): string {
const times = faker.random.number({min: 1, max: 3});
for (let i = 0; i < times; i++) {
const place = faker.random.number(name.length - 1);
name = name.replace(name[place], name[place].toUpperCase());
}
return name;
}
示例2: return
export const makeBook = (authorId: number): BookModel => {
return (new BookModel())
.setTitle(lorem.word())
.setDescription(lorem.sentences(2))
.setPrice(random.number(120) + (random.number(99) / 100))
.setPublishedAt(date.past())
.setAuthorId(authorId);
};
示例3: modifyReplaceMakeTypos
function modifyReplaceMakeTypos(name: string): string {
const times = faker.random.number({min: 1, max: 2});
for (let i = 0; i < times; i++) {
const place = faker.random.number(name.length - 1);
if (place > 0) {
name = name.replace(name[place - 1] + name[place], name[place] + name[place - 1]);
}
}
return name;
}
示例4: double
function double() {
if (l === "x" && faker.random.number(3) === 0) {
// add d so it will look like xD
l2 = l2 === "x" ? "d" : "D";
}
let start = l1 + l2;
if (faker.random.number(3) === 0) {
start = "";
}
return `${start}${name}${l2}${l1}`;
}
示例5: getRandomPerson
export function getRandomPerson(options: GetRandomPersonOptions) {
const opts: GetRandomPersonOptions = options || {};
opts.maxDateOfBirth = opts.maxDateOfBirth || new Date(Date.now() - MS_IN_YEAR);
opts.minAge = opts.minAge || 18;
opts.maxAge = opts.maxAge || 105;
opts.depth = opts.depth || 0;
// Generates a family tree...of sorts
const result: Person = {
name: faker.name.lastName() + faker.name.firstName(),
employment: {
companyName: faker.company.companyName()
},
regex: /a/g,
age: faker.random.number(),
dateOfBirth: faker.date.past(),
enrolledToVote: faker.random.boolean(),
};
if (opts.depth > 0) {
result.parents = [
getRandomPerson({ depth: opts.depth - 1 }),
getRandomPerson({ depth: opts.depth - 1 })
];
}
return result;
}
示例6:
const createChannel = () => {
return {
id: faker.random.uuid(),
name: faker.random.word(),
direct: faker.random.boolean(),
unseenMessages: faker.random.boolean() ? faker.random.number(30) : 0
};
};
示例7: modifyAddWrap
function modifyAddWrap(name: string): string {
let lengthAvailable = characterConfig.MAX_NAME_LENGTH - name.length;
let l, l1, l2, l3;
l = faker.random.arrayElement(WRAP_LETTERS);
l1 = faker.random.number(2) === 0 ? l.toUpperCase() : l;
l2 = faker.random.number(2) === 0 ? l.toUpperCase() : l;
l3 = faker.random.number(2) === 0 ? l.toUpperCase() : l;
switch (lengthAvailable) {
case 0: case 1: return name;
case 2: case 3: return single();
case 4: case 5: return double();
default: case 6: case 7:
switch (faker.random.number(2)) {
case 0: return single();
case 1: return double();
default: case 2: return triple();
}
}
function single() {
return `${l1}${name}${l1}`;
}
function double() {
if (l === "x" && faker.random.number(3) === 0) {
// add d so it will look like xD
l2 = l2 === "x" ? "d" : "D";
}
let start = l1 + l2;
if (faker.random.number(3) === 0) {
start = "";
}
return `${start}${name}${l2}${l1}`;
}
function triple() {
return `${l1}${l2}${l3}${name}${l3}${l2}${l1}`;
}
}
示例8: function
const getRandomPeople = function(count: number) : Person[] {
const people = [];
for (let ctr=0; ctr<count;ctr++) {
people.push({
name: faker.name.firstName(),
height: faker.random.number({min: 40, max: 88})
});
}
return people;
};
示例9: getBaseName
function getBaseName(isMale: boolean): string {
const gender = getMaleNumber(isMale);
const random = faker.random.number(3);
switch (random) {
default: case 0: return faker.name.firstName(gender);
case 1: return faker.name.lastName(gender);
case 2:
const firstName = faker.name.firstName(gender);
const lastName = faker.name.lastName(gender);
const name = firstName + lastName;
return name.length > characterConfig.MAX_NAME_LENGTH ? firstName : name;
}
}
示例10: modifyAddNumber
function modifyAddNumber(name: string): string {
let lengthAvailable = characterConfig.MAX_NAME_LENGTH - name.length;
switch (lengthAvailable) {
case 0: return name;
case 1: return name + faker.random.number(9);
case 2: return name + (faker.random.number(9) === 0 ? 69 : faker.random.number(99));
case 3: case 4:
const random = faker.random.number(29);
return name + (random > 6 ? faker.random.number(999) : 123 + random * 111);
default: return name + faker.random.number(10 ** faker.random.number({min: 1, max: 5}) - 1);
}
}