MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / randomString

Function randomString

apps/web/src/scripts/usage/benchmark-insert-usage.ts:21–32  ·  view source on GitHub ↗
(avgLen: number, minLen: number, maxLen: number)

Source from the content-addressed store, hash-verified

19}
20
21function randomString(avgLen: number, minLen: number, maxLen: number): string {
22 const len = Math.max(
23 minLen,
24 Math.min(maxLen, Math.round(avgLen + (Math.random() - 0.5) * (maxLen - minLen)))
25 );
26 const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_./';
27 let result = '';
28 for (let i = 0; i < len; i++) {
29 result += chars[Math.floor(Math.random() * chars.length)];
30 }
31 return result;
32}
33
34function maybeNull<T>(value: T, nullPct: number): T | null {
35 return Math.random() * 100 < nullPct ? null : value;

Callers 2

generateRandomRecordFunction · 0.85
generateStringPoolFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected