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.
62 lines
1.3 KiB
TypeScript
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(" ");
|
|
}
|
|
|