MCPcopy Create free account
hub / github.com/coder/coder / generateRandomString

Function generateRandomString

site/src/utils/random.ts:9–19  ·  view source on GitHub ↗
(bytes: number)

Source from the content-addressed store, hash-verified

7 * @see <https://developer.mozilla.org/en-US/docs/Glossary/Base64#encoded_size_increase>
8 */
9export const generateRandomString = (bytes: number): string => {
10 const byteArr = window.crypto.getRandomValues(new Uint8Array(bytes));
11 // The types for `map` don't seem to support mapping from one array type to
12 // another and `String.fromCharCode.apply` wants `number[]` so loop like this
13 // instead.
14 const strArr: string[] = [];
15 for (const byte of byteArr) {
16 strArr.push(String.fromCharCode(byte));
17 }
18 return btoa(strArr.join(""));
19};

Callers 2

UsersPageFunction · 0.90
useProxyLatencyFunction · 0.90

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected