random

23 min read

The random module of DataWizard provides you comprehensive data mocking options. Data types include basic data, text data, datetime data, color data, Web data, location data, Chinese data address, etc.. You can use it to quickly develop some data generating or auto-filling functions. The random method can be used in the following two ways.

import { random } from '@antv/data-wizard';

/** Specify the tool class */
const r = new random.BasicRandom();
r.boolean();

/* Generic class */
const r = new random;
r.boolean();

BasicRandom

The tool class BasicRandom can help you generate random basic data, including boolean, integer, float and natural number.

boolean

Generate a boolean value.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
likelihoodnumberLikelihood of true and false50-

Return value

boolean

Usage

import { random } from '@antv/data-wizard';

const r = new random;
r.boolean();
// true

integer

Generate an integer.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
minnumberMinimum-(2 ** 53 - 1)-
maxnumberMaximun2 ** 53 - 1-

Return value

number

Usage

import { random } from '@antv/data-wizard';

const r = new random.BasicRandom();
r.integer({min: 1, max: 10000});
// 2

float

Generate a floating point number.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
minnumberMinimum-(2 ** 53 - 1)-
maxnumberMaximun2 ** 53 - 1-
fixednumberDecimal places4-

Return value

number

Usage

import { random } from '@antv/data-wizard';

const r = new random;
r.float();
// 5201.1997

natural

Generate a natural number.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
minnumberMinimum-(2 ** 53 - 1)-
maxnumberMaximun2 ** 53 - 1-

Return value

number

Usage

import { random } from '@antv/data-wizard';

const r = new random;
r.natural();
// 6162812464267264

TextRandom

The tool class TextRandom can help you generate random text data, including character, string, syllable, word, sentence, paragraph, name, surname, given name (givenName), phone number (phone), Chinese character (cCharacter), Chinese word (cWord), Chinese sentence (cSentence), Chinese name (cName), Chinese surname (cSurname), Chinese given name (cGivenName) and Chinese zodiac (cZodiac).

character

Generate a character.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
poolstringCandidate pool''-
numericstringCandidate numbers'0123456789'-
symbolsstringCandidate symbols'! @#$%^&*()[],.' ,-
lowerstringLowercase letters'abcdefghijklmnopqrstuvwxyz'-
upperstringUppercase letters'ABCDEFGHIJKLMNOPQRSTUVWXYZ'-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.character();
// 'U'

string

Generate a string.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
poolstringCandidate pool''-
numericstringCandidate numbers'0123456789'-
symbolsstringCandidate symbols'! @#$%^&*()[],.' ,-
lowerstringLowercase letters'abcdefghijklmnopqrstuvwxyz'-
upperstringUppercase letters'ABCDEFGHIJKLMNOPQRSTUVWXYZ'-
lengthnumberString length5 ~ 20-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.string();
// 'lly'

syllable

Generate syllables.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
capitalizebooleanCapitalize or notfalse-
lengthnumbersyllable length2 ~ 3-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.syllable();
// 'na'

word

Generate a word.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
syllablesnumberNumber of syllables1 ~ 3-
capitalizebooleanCapitalize or notfalse-
lengthnumberWord lengthsyllables.length-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.word();
// 'homce'

sentence

Generate a sentence.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
wordsnumberNumber of words12 ~ 18-
punctuationboolean | stringPunctuationtrue-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.sentence();
// 'Uwo ek enmodo si ga ci jubhuh gun mupvebok se noadicom im esoju bimmeg ro!'

paragraph

Generate a paragraph.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
sentencenumberNumber of sentences3 ~ 7-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.paragraph();
// 'Dej etfa tassap hiwkoop sak des hol renobew nalcam igabec izizela saifovon gokfojo dewek navvore. Kaz oveiguso zomcesuf ak zigot mu badavine ti ohi me pevkidbin tovco sesop wewenew laga nud. Uzodavzic junciwpaf cuncava idno bamijih amowucele ro bejbuvgit uf puwuc gij bamlor las. Atezuh kit jef ir dohoko wovewhan juen gerzir ekega nubil sakozife hizul wa oloziru. Zuricpa oh kiziwviz baculser dijkavcub hufasgol jevot vowatur ziatru kaviztaw piz vulgokah nek. Adtomduv sor muvab hitsej habatrud pevajad netos sobertaf cawfukuk fasoc rauj ej aloras oksula seljaj mun ic.'

name

Generate a name.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
gender'male' | 'female'Gender--

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.name();
// 'Gregory Becker'

surname

Generate a surname.

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.surname();
// 'Terry'

givenName

Generate a given name.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
gender'male' | 'female'Gender--

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.givenName();
// 'Hulda'

phone

Generate a phone number.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
mobilebooleanMobile phone or landlinetrue-
formattedbooleanFormatted or notfalse-
asteriskbooleanAdd * to avoid generating real phone numbersfalse-
startNumstringPhone number prefix, only the first three digits can be specified''-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.phone({asterisk: true});
// '182****8595'

cCharacter

Generate a Chinese character.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
poolstringCandidate pool''-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.cCharacter();
// '心'

cWord

Generate a Chinese word.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
poolstringCandidate pool''-
lengthnumberWord length2~6-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.cWord();
// '质可'

cSentence

Generate a Chinese sentence.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
minnumberMinimum number of characters10-
maxnumberMaximum number of characters18-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.cSentence();
// '始法建克六天老史存王者些已研八快受术速些程理还改提部声华现等下算率明分没千些样社水争马路部越书采见代家。'

cParagraph

Generate a Chinese paragraph.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
minnumberMinimum number of sentences3-
maxnumberMaximun number of sentences18-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.cParagraph();
// '三眼形用下花机行须六准与价看号先即年设团成厂候点委各题路转过划识结。产音道机取族议料历样县具之安列金动名交构队统每水列报时了立对五一清此音话和红品例形关铁米长事群各拉油那山运知命号。'

cName

Generate a Chinese name.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
gender'male' | 'female'Gender--

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.cName();
// '奉利学'

cSurname

Generate a Chinese surname.

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.cSurname();
// '林'

cGivenName

Generate a Chinese name.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
gender'male' | 'female'Gender--

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.givenName();
// '君妍'

cZodiac

Generate a zodiac.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
locale'zh-CN' | 'en-US'i18n--

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.TextRandom();
r.cZodiac();
// '牛'

DateTimeRandom

The tool class DateTimeRandom can help you generate random datetime data, including date, time, datetime, timestamp, weekday, month.

date

Generate a date.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
minnumberMinimum timestamp0-
maxnumberMaximum timestampnew Date().getTime()-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.DateTimeRandom();
r.date();
// '1989-11-30'

time

Generate a time.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
shortbooleanUTC offsetfalse-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.DateTimeRandom();
r.time();
// '04:09:02+08:00'

datetime

Generate a datetime.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
minnumberMinimum timestamp0-
maxnumberMaximum timestampnew Date().getTime()-
formatstringFormatting (refer to date-fns format)yyyy-MM-dd'T'HH:mm:ssXXX-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.DateTimeRandom();
r.datetime();
// '2019-01-23T09:54:06+08:00'

timestamp

Generate a timestamp.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
minnumberMinimum timestamp0-
maxnumberMaximum timestampnew Date().getTime()-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.DateTimeRandom();
r.timestamp();
// '796136687217'

weekday

Generate a weekday.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
locale'zh-CN' | 'en-US'i18n'en-US'-
abbrbooleanAbbreviationfalse-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.DateTimeRandom();
r.weekday();
// 'Friday'

month

Generate a month.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
locale'zh-CN' | 'en-US'i18n'en-US'-
abbrbooleanAbbreviationfalse-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.DateTimeRandom();
r.month();
// 'February'

ColorRandom

The tool class ColorRandom can help you generate random color data, including RGB color (rgb), rgba color (rgba), HSL color (hsl), hsla color (hsla), color name (colorName), hex color (hexColor) and decimal color (decimalColor).

rgb

Generate a RGB color.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
grayscalebooleanGrayscalefalse-
minnumberMinimum0-
maxnumberMaximum255-
minRnumberMinimum red valuemin-
maxRnumberMaximum red valuemax-
maxGnumberMinimum green valuemin-
maxGnumberMaximum green valuemax-
maxBnumberMinimum blue valuemin-
maxBnumberMaximum blue valuemax-
casing'lower' | 'upper'Caselower-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.ColorRandom();
r.rgb();
// 'rgb(202,80,38)'

rgba

Generate a rgba color.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
grayscalebooleanGrayscalefalse-
minnumberMinimum0-
maxnumberMaximum255-
minRnumberMinimum red valuemin-
maxRnumberMaximum red valuemax-
maxGnumberMinimum green valuemin-
maxGnumberMaximum green valuemax-
maxBnumberMinimum blue valuemin-
maxBnumberMaximum blue valuemax-
casing'lower' | 'upper'Caselower-
minAnumberMinimum transparencylower-
maxAnumberMaximum transparencylower-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.ColorRandom();
r.rgba();
// 'rgba(197,205,189,0.5376)'

hsl

Generate a HSL color.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
minHnumberMinimum hue0-
maxHnumberMaximum hue360-
maxSnumberMinimum saturation0-
maxSnumberMaximum saturation100-
minLnumberMinimum lightness0-
maxLnumberMaximum lightness100-
casing'lower' | 'upper'Caselower-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.ColorRandom();
r.hsl();
// 'hsl(72,8.5613%,29.6035%)'

hsla

Generate a hsla color.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
minHnumberMinimum hue0-
maxHnumberMaximum hue360-
maxSnumberMinimum saturation0-
maxSnumberMaximum saturation100-
minLnumberMinimum lightness0-
maxLnumberMaximum lightness100-
casing'lower' | 'upper'Caselower-
minAnumberMinimum transparencylower-
maxAnumberMaximum transparencylower-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.ColorRandom();
r.hsla();
// 'hsla(268,98.9866%,6.9809%,0.5648)'

colorName

Generate a color name.

Return value

string

Reference MDN color

Usage

import { random } from '@antv/data-wizard';

const r = new random.ColorRandom();
r.colorName();
// 'white'

hexColor

Generate a hexadecimal color.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
grayscalebooleanGrayscalefalse-
minnumberMinimum0-
maxnumberMaximum255-
minRnumberMinimum red valuemin-
maxRnumberMaximum red valuemax-
maxGnumberMinimum green valuemin-
maxGnumberMaximum green valuemax-
maxBnumberMinimum blue valuemin-
maxBnumberMaximum blue valuemax-
casing'lower' | 'upper'Caselower-
prefixbooleanWhether to show # prefixfalse-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.ColorRandom();
r.hexColor();
// '#0216ff'

demicalColor

Generate a decimal color.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
grayscalebooleanGrayscalefalse-
minnumberMinimum0-
maxnumberMaximum255-
minRnumberMinimum red valuemin-
maxRnumberMaximum red valuemax-
maxGnumberMinimum green valuemin-
maxGnumberMaximum green valuemax-
maxBnumberMinimum blue valuemin-
maxBnumberMaximum blue valuemax-
casing'lower' | 'upper'Caselower-

Return value

number

Usage

import { random } from '@antv/data-wizard';

const r = new random.ColorRandom();
r.decimalColor();
// '12272614'

WebRandom

The tool class WebRandom can help you generate random Web data, including top-level domain (tld), domain name (domain), Uniform Resource Locator (url), IPv4 address (ipv4), IPv6 address (ipv6), and email address (email).

tld

Generate a top-level domain.

Return value

string

Reference TLD

Usage

import { random } from '@antv/data-wizard';

const r = new random.WebRandom();
r.tld();
// 'uz'

domain

Generate a domain name.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
tldstringTop-level domain--

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.WebRandom();
r.domain();
// 'pujan.ee'

url

Generate a Uniform Resource Locator.

Parameters

options Configuration options optional

PropertyTypeDescriptionDefaultRequired
tldstringTop-level domain--
protocolstringProtocol'http'-
domainstringDomain name--
domainPrefixstringDomain prefix''-
pathstringPath--
extensionsstring[]File extensionsany[]-

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.WebRandom();
r.url();
// 'http://alo.tg/vivso'

ipv4

Generate an IPv4 address.

Return value

string

Usage

import { random } from '@antv/data-wizard';

const r = new random.WebRandom();
r.ipv4();
// '181.212.214.48'

ipv6

Generate an IPv6 address.

Return value

string

Usage

import { random } from '@antv/data-wizard';