MCPcopy Index your code
hub / github.com/ulid/javascript / randomChar

Function randomChar

source/utils.ts:4–10  ·  view source on GitHub ↗
(prng: PRNG)

Source from the content-addressed store, hash-verified

2import { PRNG } from "./types.js";
3
4export function randomChar(prng: PRNG): string {
5 // Currently PRNGs generate fractions from 0 to _less than_ 1, so no "%" is necessary.
6 // However, just in case a future PRNG can generate 1,
7 // we are applying "% ENCODING LEN" to wrap back to the first character
8 const randomPosition = Math.floor(prng() * ENCODING_LEN) % ENCODING_LEN;
9 return ENCODING.charAt(randomPosition);
10}
11
12export function replaceCharAt(str: string, index: number, char: string): string {
13 if (index > str.length - 1) {

Callers 1

encodeRandomFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected