or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

ajax-mocking.mddata-generation.mddata-validation.mdindex.mdrandom-data.mdutilities.md

random-data.mddocs/

0

# Random Data

1

2

Extensive collection of random data generators for creating realistic fake data including basic types, names, addresses, dates, web data, and more. All functions are accessible through `Mock.Random`.

3

4

## Capabilities

5

6

### Basic Data Types

7

8

Core random data generators for primitive types and basic structures.

9

10

```javascript { .api }

11

/**

12

* Generate random boolean value

13

* @param min - Minimum probability weight (default: 1)

14

* @param max - Maximum probability weight (default: 1)

15

* @param current - Current value to use for probability calculation

16

* @returns Random boolean

17

*/

18

Mock.Random.boolean(min?: number, max?: number, current?: boolean): boolean;

19

Mock.Random.bool(min?: number, max?: number, current?: boolean): boolean; // Alias

20

21

/**

22

* Generate random natural number (>= 0)

23

* @param min - Minimum value (default: 0)

24

* @param max - Maximum value (default: 9007199254740992)

25

* @returns Random natural number

26

*/

27

Mock.Random.natural(min?: number, max?: number): number;

28

29

/**

30

* Generate random integer

31

* @param min - Minimum value (default: -9007199254740992)

32

* @param max - Maximum value (default: 9007199254740992)

33

* @returns Random integer

34

*/

35

Mock.Random.integer(min?: number, max?: number): number;

36

Mock.Random.int(min?: number, max?: number): number; // Alias

37

38

/**

39

* Generate random floating point number

40

* @param min - Minimum integer part

41

* @param max - Maximum integer part

42

* @param dmin - Minimum decimal places (default: 0)

43

* @param dmax - Maximum decimal places (default: 17)

44

* @returns Random float

45

*/

46

Mock.Random.float(min?: number, max?: number, dmin?: number, dmax?: number): number;

47

48

/**

49

* Generate random character

50

* @param pool - Character pool ('lower', 'upper', 'number', 'symbol', or custom string)

51

* @returns Random character

52

*/

53

Mock.Random.character(pool?: string): string;

54

Mock.Random.char(pool?: string): string; // Alias

55

56

/**

57

* Generate random string

58

* @param pool - Character pool or length (if number)

59

* @param min - Minimum length

60

* @param max - Maximum length

61

* @returns Random string

62

*/

63

Mock.Random.string(pool?: string | number, min?: number, max?: number): string;

64

Mock.Random.str(pool?: string | number, min?: number, max?: number): string; // Alias

65

66

/**

67

* Generate range of integers

68

* @param start - Start value

69

* @param stop - Stop value

70

* @param step - Step increment (default: 1)

71

* @returns Array of integers

72

*/

73

Mock.Random.range(start: number, stop?: number, step?: number): number[];

74

```

75

76

**Basic Examples:**

77

78

```javascript

79

// Boolean values

80

Mock.Random.boolean(); // true or false

81

Mock.Random.bool(1, 2, true); // 1:2 ratio for keeping true

82

83

// Numbers

84

Mock.Random.natural(1, 100); // 1 to 100

85

Mock.Random.integer(-50, 50); // -50 to 50

86

Mock.Random.float(0, 10, 2, 4); // 0.xx to 10.xxxx

87

88

// Characters and strings

89

Mock.Random.character('lower'); // 'a' to 'z'

90

Mock.Random.string('number', 6); // '123456'

91

Mock.Random.string(5, 10); // 5-10 character string

92

93

// Ranges

94

Mock.Random.range(5); // [0, 1, 2, 3, 4]

95

Mock.Random.range(2, 8, 2); // [2, 4, 6]

96

```

97

98

### Date and Time

99

100

Generators for dates, times, and formatted datetime strings.

101

102

```javascript { .api }

103

/**

104

* Generate random date string

105

* @param format - Date format (default: 'yyyy-MM-dd')

106

* @returns Formatted date string

107

*/

108

Mock.Random.date(format?: string): string;

109

110

/**

111

* Generate random time string

112

* @param format - Time format (default: 'HH:mm:ss')

113

* @returns Formatted time string

114

*/

115

Mock.Random.time(format?: string): string;

116

117

/**

118

* Generate random datetime string

119

* @param format - DateTime format (default: 'yyyy-MM-dd HH:mm:ss')

120

* @returns Formatted datetime string

121

*/

122

Mock.Random.datetime(format?: string): string;

123

124

/**

125

* Get current time with optional formatting and unit precision

126

* @param unit - Time unit for precision ('year', 'month', 'day', 'hour', 'minute', 'second', 'week')

127

* @param format - Output format (default: 'yyyy-MM-dd HH:mm:ss')

128

* @returns Formatted current time

129

*/

130

Mock.Random.now(unit?: string, format?: string): string;

131

```

132

133

**Date Examples:**

134

135

```javascript

136

// Basic dates

137

Mock.Random.date(); // "2023-05-15"

138

Mock.Random.time(); // "14:30:22"

139

Mock.Random.datetime(); // "2023-05-15 14:30:22"

140

141

// Custom formats

142

Mock.Random.date('MM/dd/yyyy'); // "05/15/2023"

143

Mock.Random.time('HH:mm'); // "14:30"

144

Mock.Random.datetime('yyyy年MM月dd日'); // "2023年05月15日"

145

146

// Current time

147

Mock.Random.now(); // Current time formatted

148

Mock.Random.now('day'); // Current day start

149

Mock.Random.now('month', 'yyyy-MM'); // Current month start

150

```

151

152

### Text Generation

153

154

Generators for words, sentences, paragraphs, and titles in English and Chinese.

155

156

```javascript { .api }

157

/**

158

* Generate random word

159

* @param min - Minimum length (default: 3)

160

* @param max - Maximum length (default: 10)

161

* @returns Random word

162

*/

163

Mock.Random.word(min?: number, max?: number): string;

164

165

/**

166

* Generate random sentence

167

* @param min - Minimum word count (default: 12)

168

* @param max - Maximum word count (default: 18)

169

* @returns Random sentence with period

170

*/

171

Mock.Random.sentence(min?: number, max?: number): string;

172

173

/**

174

* Generate random paragraph

175

* @param min - Minimum sentence count (default: 3)

176

* @param max - Maximum sentence count (default: 7)

177

* @returns Random paragraph

178

*/

179

Mock.Random.paragraph(min?: number, max?: number): string;

180

181

/**

182

* Generate random title

183

* @param min - Minimum word count (default: 3)

184

* @param max - Maximum word count (default: 7)

185

* @returns Random title with capitalized words

186

*/

187

Mock.Random.title(min?: number, max?: number): string;

188

189

// Chinese text generators

190

Mock.Random.cword(pool?: string, min?: number, max?: number): string; // Chinese word(s)

191

Mock.Random.csentence(min?: number, max?: number): string; // Chinese sentence

192

Mock.Random.cparagraph(min?: number, max?: number): string; // Chinese paragraph

193

Mock.Random.ctitle(min?: number, max?: number): string; // Chinese title

194

```

195

196

### Names

197

198

Generators for personal names in English and Chinese.

199

200

```javascript { .api }

201

/**

202

* Generate random first name

203

* @returns Random first name

204

*/

205

Mock.Random.first(): string;

206

207

/**

208

* Generate random last name

209

* @returns Random last name

210

*/

211

Mock.Random.last(): string;

212

213

/**

214

* Generate random full name

215

* @param middle - Include middle name (default: false)

216

* @returns Random full name

217

*/

218

Mock.Random.name(middle?: boolean): string;

219

220

// Chinese name generators

221

Mock.Random.cfirst(): string; // Chinese first name

222

Mock.Random.clast(): string; // Chinese last name

223

Mock.Random.cname(): string; // Chinese full name

224

```

225

226

### Web Data

227

228

Generators for URLs, domains, emails, and IP addresses.

229

230

```javascript { .api }

231

/**

232

* Generate random URL

233

* @param protocol - URL protocol (default: random)

234

* @param host - Host name (default: random domain)

235

* @returns Random URL

236

*/

237

Mock.Random.url(protocol?: string, host?: string): string;

238

239

/**

240

* Generate random protocol

241

* @returns Random protocol (http, ftp, etc.)

242

*/

243

Mock.Random.protocol(): string;

244

245

/**

246

* Generate random domain

247

* @param tld - Top-level domain (optional)

248

* @returns Random domain name

249

*/

250

Mock.Random.domain(tld?: string): string;

251

252

/**

253

* Generate random top-level domain

254

* @returns Random TLD (.com, .org, etc.)

255

*/

256

Mock.Random.tld(): string;

257

258

/**

259

* Generate random email address

260

* @param domain - Email domain (default: random)

261

* @returns Random email address

262

*/

263

Mock.Random.email(domain?: string): string;

264

265

/**

266

* Generate random IP address

267

* @returns Random IPv4 address

268

*/

269

Mock.Random.ip(): string;

270

```

271

272

### Address Data

273

274

Generators for geographical locations and addresses.

275

276

```javascript { .api }

277

/**

278

* Generate random region name

279

* @returns Random region

280

*/

281

Mock.Random.region(): string;

282

283

/**

284

* Generate random province name

285

* @returns Random province

286

*/

287

Mock.Random.province(): string;

288

289

/**

290

* Generate random city name

291

* @param prefix - Include province prefix

292

* @returns Random city name

293

*/

294

Mock.Random.city(prefix?: boolean): string;

295

296

/**

297

* Generate random county name

298

* @param prefix - Include city prefix

299

* @returns Random county name

300

*/

301

Mock.Random.county(prefix?: boolean): string;

302

303

/**

304

* Generate random postal/zip code

305

* @param len - Length of zip code (default: 6)

306

* @returns Random zip code

307

*/

308

Mock.Random.zip(len?: number): string;

309

```

310

311

### Colors

312

313

Generators for color values in various formats.

314

315

```javascript { .api }

316

/**

317

* Generate random color

318

* @param name - Named color to return (optional)

319

* @returns Random color name or specified named color

320

*/

321

Mock.Random.color(name?: string): string;

322

323

/**

324

* Generate random hex color

325

* @returns Random hex color (#rrggbb)

326

*/

327

Mock.Random.hex(): string;

328

329

/**

330

* Generate random RGB color

331

* @returns Random RGB color string

332

*/

333

Mock.Random.rgb(): string;

334

335

/**

336

* Generate random RGBA color

337

* @returns Random RGBA color string

338

*/

339

Mock.Random.rgba(): string;

340

341

/**

342

* Generate random HSL color

343

* @returns Random HSL color string

344

*/

345

Mock.Random.hsl(): string;

346

```

347

348

### Images

349

350

Generators for image URLs and data URIs.

351

352

```javascript { .api }

353

/**

354

* Generate random image URL

355

* @param size - Image size (default: random ad size)

356

* @param background - Background color (default: random)

357

* @param foreground - Foreground/text color (default: random)

358

* @param format - Image format (default: 'png')

359

* @param text - Image text (default: size)

360

* @returns Random image URL

361

*/

362

Mock.Random.image(size?: string, background?: string, foreground?: string, format?: string, text?: string): string;

363

Mock.Random.img(size?: string, background?: string, foreground?: string, format?: string, text?: string): string; // Alias

364

365

/**

366

* Generate random data URI image (base64 encoded)

367

* @param size - Image size (default: random ad size)

368

* @param text - Image text (default: size)

369

* @returns Random data URI image as base64 string

370

*/

371

Mock.Random.dataImage(size?: string, text?: string): string;

372

```

373

374

### Utility Functions

375

376

Helper functions for array manipulation and data transformation.

377

378

```javascript { .api }

379

/**

380

* Capitalize first letter of string

381

* @param word - Input string

382

* @returns Capitalized string

383

*/

384

Mock.Random.capitalize(word: string): string;

385

386

/**

387

* Convert string to uppercase

388

* @param str - Input string

389

* @returns Uppercase string

390

*/

391

Mock.Random.upper(str: string): string;

392

393

/**

394

* Convert string to lowercase

395

* @param str - Input string

396

* @returns Lowercase string

397

*/

398

Mock.Random.lower(str: string): string;

399

400

/**

401

* Pick random element(s) from array

402

* @param array - Source array or individual arguments

403

* @param min - Minimum count (default: 1)

404

* @param max - Maximum count (default: 1)

405

* @returns Random element or array of elements

406

*/

407

Mock.Random.pick(array: any[] | any, min?: number, max?: number): any;

408

409

/**

410

* Shuffle array elements

411

* @param array - Array to shuffle

412

* @returns Shuffled array

413

*/

414

Mock.Random.shuffle(array: any[]): any[];

415

```

416

417

### Miscellaneous

418

419

Additional generators for IDs, dice rolls, and special values.

420

421

```javascript { .api }

422

// Dice generators

423

Mock.Random.d4(): number; // 1-4

424

Mock.Random.d6(): number; // 1-6

425

Mock.Random.d8(): number; // 1-8

426

Mock.Random.d12(): number; // 1-12

427

Mock.Random.d20(): number; // 1-20

428

Mock.Random.d100(): number; // 1-100

429

430

/**

431

* Generate GUID/UUID

432

* @returns Random GUID string

433

*/

434

Mock.Random.guid(): string;

435

Mock.Random.uuid(): string; // Alias

436

437

/**

438

* Generate Chinese 18-digit ID card number

439

* @returns Random Chinese ID card number

440

*/

441

Mock.Random.id(): string;

442

443

/**

444

* Generate increment value (auto-incrementing counter)

445

* @param step - Increment step (default: 1)

446

* @returns Incremented value

447

*/

448

Mock.Random.increment(step?: number): number;

449

450

/**

451

* Alias for increment function

452

* @param step - Increment step (default: 1)

453

* @returns Incremented value

454

*/

455

Mock.Random.inc(step?: number): number;

456

```