Kaynağa Gözat

docs: update `randRange()` and `randomId()`

Sv443 5 ay önce
ebeveyn
işleme
27c6fed6d4
1 değiştirilmiş dosya ile 19 ekleme ve 12 silme
  1. 19 12
      README.md

+ 19 - 12
README.md

@@ -957,21 +957,25 @@ mapRange(4, 0, 13, 0, 100); // 30.76923076923077
 ### randRange()
 Usages:  
 ```ts
-randRange(min: number, max: number): number
-randRange(max: number): number
+randRange(min: number, max: number, enhancedEntropy?: boolean): number
+randRange(max: number, enhancedEntropy?: boolean): number
 ```
   
 Returns a random number between `min` and `max` (inclusive).  
 If only one argument is passed, it will be used as the `max` value and `min` will be set to 0.  
   
+If `enhancedEntropy` is set to true (false by default), the [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues) is used for generating the random numbers.  
+Note that this takes MUCH longer, but the generated IDs will have a higher entropy.  
+  
 <details><summary><b>Example - click to view</b></summary>
 
 ```ts
 import { randRange } from "@sv443-network/userutils";
 
-randRange(0, 10);  // 4
-randRange(10, 20); // 17
-randRange(10);     // 7
+randRange(0, 10);       // 4
+randRange(10, 20);      // 17
+randRange(10);          // 7
+randRange(0, 10, true); // 4 (the devil is in the details)
 ```
 </details>
 
@@ -1904,7 +1908,7 @@ run();
 ### randomId()
 Usage:  
 ```ts
-randomId(length?: number, radix?: number, enhancedEntropy?: boolean): string
+randomId(length?: number, radix?: number, enhancedEntropy?: boolean, randomCase?: boolean): string
 ```
   
 Generates a random ID of a given length and [radix (base).](https://en.wikipedia.org/wiki/Radix)  
@@ -1916,18 +1920,21 @@ Use 2 for binary, 8 for octal, 10 for decimal, 16 for hexadecimal and 36 for alp
 If `enhancedEntropy` is set to true (false by default), the [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues) is used for generating the random numbers.  
 Note that this takes MUCH longer, but the generated IDs will have a higher entropy.  
   
-⚠️ Not suitable for generating anything related to cryptography! Use [SubtleCrypto's `generateKey()`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey) for that instead.  
+If `randomCase` is set to true (which it is by default), the generated ID will contain both upper and lower case letters.  
+This randomization is also affected by the `enhancedEntropy` setting, unless there are no alphabetic characters in the output in which case it will be skipped.  
+  
+⚠️ This is not suitable for generating anything related to cryptography! Use [SubtleCrypto's `generateKey()`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey) for that instead.  
   
 <details><summary><b>Example - click to view</b></summary>
 
 ```ts
 import { randomId } from "@sv443-network/userutils";
 
-randomId();       // "1bda419a73629d4f" (length 16, radix 16)
-randomId(10);     // "f86cd354a4"       (length 10, radix 16)
-randomId(10, 2);  // "1010001101"       (length 10, radix 2)
-randomId(10, 10); // "0183428506"       (length 10, radix 10)
-randomId(10, 36); // "z46jfpa37r"       (length 10, radix 36)
+randomId();                    // "1bda419a73629d4f" (length 16, radix 16)
+randomId(10);                  // "f86cd354a4"       (length 10, radix 16)
+randomId(10, 2);               // "1010001101"       (length 10, radix 2)
+randomId(10, 10);              // "0183428506"       (length 10, radix 10)
+randomId(10, 36, false, true); // "z46jFPa37R"       (length 10, radix 36, random case)
 ```
 </details>