getRandomString
Generates a random string using specified radix conversion. Creates pseudo-random strings by converting Math.random() output to the specified radix and removing the '0.' prefix. Higher radix values produce shorter strings with more character variety.
Signature
const getRandomString: (radix?: number) => string
Parameters
| Name | Type | Description |
|---|---|---|
radix | - | Base for number conversion (2-36, defaults to 32) |
Returns
Random string without decimal prefix
Examples
String generation
import { getRandomString } from '@winglet/common-utils';
console.log(getRandomString()); // 'k2j4h7m' (base 32)
console.log(getRandomString(16)); // 'a7f3d9e2' (hexadecimal)
console.log(getRandomString(36)); // 'xyz123' (alphanumeric)
Playground
import { getRandomString } from '@winglet/common-utils'; console.log(getRandomString()); // 'k2j4h7m' (base 32) console.log(getRandomString(16)); // 'a7f3d9e2' (hexadecimal) console.log(getRandomString(36)); // 'xyz123' (alphanumeric)