🔡 Generates a random string of a specified length using a given character set.
Syntax
TypeScript
import { randomString } from '@opentf/std'; randomString( length: number = 10, chars: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ): string;
Parameters
length: The length of the string.chars: The character set to use.
length must be a non-negative integer, and chars must not be empty.
Returns
A random string.
Examples
TypeScript
randomString() //=> 'kL8mP2nQ1r' randomString(5, '0123456789') //=> '48291'