Files
3dverse-testtask/tests/utils.ts
T
didier amyot 0d627c9051 Added a very complicated AsyncIterableReader class.
The class was already implemented in
"https://deno.land/std@0.144.0/streams/conversion.ts".  So, I litterally
lost 1 day of work!  I hate myself.
2023-06-12 12:02:15 -04:00

62 lines
1.3 KiB
TypeScript

export function* randomNumbers(seed: number, max: number, maxResult: number|undefined = undefined) : Generator<number> {
const a = 48271;
const m = 2147483647;
max = Math.floor(max);
let i = 0;
while (true) {
seed = (a * seed) % m;
yield seed % max;
i ++;
if(maxResult !== undefined && i >= maxResult){
return;
}
}
}
export function range(min: number, max: number): number[]{
const ret = []
for(let i = min; i < max; i ++){
ret.push(i);
}
return ret;
}
export function generateLargeText(seed: number, size: number): string {
const words = [
"Norway",
"Germany",
"Ecuador",
"Chile",
"Colombia",
"Sri Lanka",
"Guinea",
"United Kingdom",
"Egypt",
"Palau",
"Latvia",
"Congo, Democratic Republic of the",
"Malawi",
"Senegal",
"Trinidad and Tobago",
"Guatemala",
"Chad",
"New Zealand",
"Malaysia",
"Lithuania",
"Taiwan",
"Solomon Islands",
"Grenada",
"Hungary",
"Korea, South",
];
let ret: string[] = [];
for (let i = 0; i < size; i++) {
seed = (seed * 4931 + 2753) % words.length;
ret.push(words[seed]);
}
return ret.join(" ");
}