Skip to content

Commit

Permalink
simplify randomizer initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
lmdulz committed Sep 23, 2024
1 parent d4eabd4 commit 7ee4a7e
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/randomizer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// import { getRandomValues } from "crypto";
// import crypto from "crypto";

class Randomizer {
private seed: string;

constructor(seed = "") {
if (seed == "") {
constructor(seed?) {
if (seed == undefined) {
this.seed = this.generateRandomSeed();
} else {
this.seed = seed;
Expand All @@ -18,7 +21,7 @@ class Randomizer {

private async calculateSHADigestWeb(array: Uint8Array): Promise<Uint8Array> {
// if (typeof window !== "undefined") {
const hashBuffer = await window.crypto.subtle.digest("SHA-256", array);
const hashBuffer = await window.crypto.subtle.digest("SHA-1", array);
return new Promise((resolve) => {
resolve(new Uint8Array(hashBuffer));
});
Expand Down Expand Up @@ -51,9 +54,7 @@ class Randomizer {
// getRandomValues(randomValues);
// }

const seed = Array.from(randomValues, (byte) =>
byte.toString(16).padStart(2, "0")
).join("");
const seed = Array.from(randomValues, (byte) => byte.toString(16).padStart(2, "0")).join("");

return seed;
}
Expand Down Expand Up @@ -84,10 +85,7 @@ class Randomizer {

return result;
}
public async getIntsFromRanges(
originalValue: string,
...suprema: number[]
): Promise<number[]> {
public async getIntsFromRanges(originalValue: string, ...suprema: number[]): Promise<number[]> {
let result: bigint | number[] = [];
let bigNumber = await this.toInt(originalValue);
const arr: number[] = [];
Expand Down

0 comments on commit 7ee4a7e

Please sign in to comment.