Skip to content

Commit 275020c

Browse files
committed
docs: better warning for randomId
1 parent 17a6ad5 commit 275020c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,9 @@ randomId(length?: number, radix?: number): string
824824
```
825825

826826
Generates a cryptographically strong random ID of a given length and [radix (base).](https://en.wikipedia.org/wiki/Radix)
827+
Uses the [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues) for generating the random numbers.
828+
⚠️ This is not intended for generating encryption keys, only for generating IDs with a decent amount of entropy!
829+
827830
The default length is 16 and the default radix is 16 (hexadecimal).
828831
You may change the radix to get digits from different numerical systems.
829832
Use 2 for binary, 8 for octal, 10 for decimal, 16 for hexadecimal and 36 for alphanumeric.
@@ -1273,7 +1276,7 @@ randomizeArray(array: Array): Array
12731276
```
12741277

12751278
Returns a copy of an array with its items in a random order.
1276-
If the array is empty, the originally passed empty array will be returned without copying.
1279+
If the array is empty, a new, empty array will be returned.
12771280

12781281
<details><summary><b>Example - click to view</b></summary>
12791282

lib/math.ts

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export function randRange(...args: number[]): number {
4848
/**
4949
* Generates a random ID with the specified length and radix (16 characters and hexadecimal by default)
5050
* Uses [`crypto.getRandomValues()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues) for better cryptographic randomness
51+
* ⚠️ Not suitable for generating encryption keys! Use [`crypto.subtle.generateKey()`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey) for that.
5152
* @param length The length of the ID to generate (defaults to 16)
5253
* @param radix The [radix](https://en.wikipedia.org/wiki/Radix) of each digit (defaults to 16 which is hexadecimal. Use 2 for binary, 10 for decimal, 36 for alphanumeric, etc.)
5354
*/

0 commit comments

Comments
 (0)