(avgLen: number, minLen: number, maxLen: number)
| 19 | } |
| 20 | |
| 21 | function 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 | |
| 34 | function maybeNull<T>(value: T, nullPct: number): T | null { |
| 35 | return Math.random() * 100 < nullPct ? null : value; |
no outgoing calls
no test coverage detected