generateRandomString() — supabase Function Reference
Architecture documentation for the generateRandomString() function in JwtGenerator.tsx from the supabase codebase.
Entity Profile
Dependency Diagram
graph TD 5a090369_1c3c_5ea2_b963_0aa9c80c5013["generateRandomString()"] 7bc1a88f_c0db_9a28_6231_dd969c041964["JwtGenerator()"] 7bc1a88f_c0db_9a28_6231_dd969c041964 -->|calls| 5a090369_1c3c_5ea2_b963_0aa9c80c5013 style 5a090369_1c3c_5ea2_b963_0aa9c80c5013 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
apps/docs/components/JwtGenerator/JwtGenerator.tsx lines 23–54
const generateRandomString = (length: number) => {
const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
let result = ''
/**
* The number of possible Uint8 integers is 256. Since the length of `CHARS`
* doesn't fit exactly into 256, simply taking the modulus would create an
* uneven distribution that favors the earlier characters. To make a truly
* uniform distribution, we have to discard everything above the last full
* cycle, and pick again.
*
* The minus 1 is to account for 0-indexing.
*/
const MAX = Math.floor(256 / CHARS.length) * CHARS.length - 1
const randomUInt8Array = new Uint8Array(1)
for (let i = 0; i < length; i++) {
let randomNumber: number
do {
crypto.getRandomValues(randomUInt8Array)
randomNumber = randomUInt8Array[0]
/**
* Keep picking until we get a number in the valid range.
*/
} while (randomNumber > MAX)
result += CHARS[randomNumber % CHARS.length]
}
return result
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does generateRandomString() do?
generateRandomString() is a function in the supabase codebase.
What calls generateRandomString()?
generateRandomString() is called by 1 function(s): JwtGenerator.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free