fix: pin implementation (@fehmer) (#6699)

This commit is contained in:
Christian Fehmer 2025-07-09 12:05:18 +02:00 committed by GitHub
parent 06ca8c2385
commit 6b1bbfb432
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 17 deletions

View file

@ -25,6 +25,9 @@ import {
import { WordGenError } from "../utils/word-gen-error";
import * as Loader from "../elements/loader";
//pin implementation
const random = Math.random;
function shouldCapitalize(lastChar: string): boolean {
return /[?!.؟]/.test(lastChar);
}
@ -60,7 +63,7 @@ export async function punctuateWord(
}
if (currentLanguage === "spanish") {
const rand = Math.random();
const rand = random();
if (rand > 0.9) {
word = "¿" + word;
spanishSentenceTracker = "?";
@ -70,7 +73,7 @@ export async function punctuateWord(
}
}
} else if (
(Math.random() < 0.1 &&
(random() < 0.1 &&
lastChar !== "." &&
lastChar !== "," &&
index !== maxindex - 2) ||
@ -82,7 +85,7 @@ export async function punctuateWord(
spanishSentenceTracker = "";
}
} else {
const rand = Math.random();
const rand = random();
if (rand <= 0.8) {
if (currentLanguage === "kurdish") {
word += ".";
@ -134,14 +137,14 @@ export async function punctuateWord(
}
}
} else if (
Math.random() < 0.01 &&
random() < 0.01 &&
lastChar !== "," &&
lastChar !== "." &&
currentLanguage !== "russian"
) {
word = `"${word}"`;
} else if (
Math.random() < 0.011 &&
random() < 0.011 &&
lastChar !== "," &&
lastChar !== "." &&
currentLanguage !== "russian" &&
@ -149,9 +152,9 @@ export async function punctuateWord(
currentLanguage !== "slovak"
) {
word = `'${word}'`;
} else if (Math.random() < 0.012 && lastChar !== "," && lastChar !== ".") {
} else if (random() < 0.012 && lastChar !== "," && lastChar !== ".") {
if (currentLanguage === "code") {
const r = Math.random();
const r = random();
const brackets = ["()", "{}", "[]", "<>"];
// add `word` in javascript
@ -172,7 +175,7 @@ export async function punctuateWord(
word = `(${word})`;
}
} else if (
Math.random() < 0.013 &&
random() < 0.013 &&
lastChar !== "," &&
lastChar !== "." &&
lastChar !== ";" &&
@ -189,14 +192,14 @@ export async function punctuateWord(
word += ":";
}
} else if (
Math.random() < 0.014 &&
random() < 0.014 &&
lastChar !== "," &&
lastChar !== "." &&
previousWord !== "-"
) {
word = "-";
} else if (
Math.random() < 0.015 &&
random() < 0.015 &&
lastChar !== "," &&
lastChar !== "." &&
lastChar !== ";" &&
@ -218,7 +221,7 @@ export async function punctuateWord(
} else {
word += ";";
}
} else if (Math.random() < 0.2 && lastChar !== ",") {
} else if (random() < 0.2 && lastChar !== ",") {
if (
currentLanguage === "arabic" ||
currentLanguage === "urdu" ||
@ -233,7 +236,7 @@ export async function punctuateWord(
} else {
word += ",";
}
} else if (Math.random() < 0.25 && currentLanguage === "code") {
} else if (random() < 0.25 && currentLanguage === "code") {
const specials = ["{", "}", "[", "]", "(", ")", ";", "=", "+", "%", "/"];
const specialsC = [
"{",
@ -284,7 +287,7 @@ export async function punctuateWord(
}
}
} else if (
Math.random() < 0.5 &&
random() < 0.5 &&
currentLanguage === "english" &&
(await EnglishPunctuation.check(word))
) {
@ -907,7 +910,7 @@ export async function getNextWord(
);
}
if (Config.numbers) {
if (Math.random() < 0.1) {
if (random() < 0.1) {
randomWord = GetText.getNumbers(4);
if (Config.language.startsWith("kurdish")) {

View file

@ -2,6 +2,9 @@ import { FunboxName } from "@monkeytype/contracts/schemas/configs";
import { Language } from "@monkeytype/contracts/schemas/languages";
import { Accents } from "../test/lazy-mode";
//pin implementation
const fetch = window.fetch;
/**
* Fetches JSON data from the specified URL using the fetch API.
* @param url - The URL to fetch the JSON data from.

View file

@ -1,3 +1,8 @@
//pin implementations
const random = Math.random;
const ceil = Math.ceil;
const floor = Math.floor;
/**
* Rounds a number to one decimal places.
* @param num The number to round.
@ -85,9 +90,9 @@ export function kogasa(cov: number): number {
* @returns Random integer betwen min and max.
*/
export function randomIntFromRange(min: number, max: number): number {
const minNorm = Math.ceil(min);
const maxNorm = Math.floor(max);
return Math.floor(Math.random() * (maxNorm - minNorm + 1) + minNorm);
const minNorm = ceil(min);
const maxNorm = floor(max);
return floor(random() * (maxNorm - minNorm + 1) + minNorm);
}
/**