-3

So i have this code but somehow console.log doesnt work, I cant tell if its bugged or just loading because it uses alot of memory and doesn't show any errors Here's the code:

function deterministicRandom(seed) {
  let x = Math.sin(seed) * 10000;
  return x - Math.floor(x);
}

const seed = 1234; // Your desired seed value
const test = {};

for (let i = 32; i <= 126; i++) {
  const char = String.fromCharCode(i);
  let randomNum = Math.floor(deterministicRandom(seed + i) * 100000) + 1;

  while (Object.values(test).includes(randomNum)) {
    randomNum = Math.floor(deterministicRandom(randomNum) * 100000) + 1;
  }

  test[char] = randomNum;

  for (let j = 32; j <= 126; j++) {
    const doubleChar = char + String.fromCharCode(j);
    let doubleRandomNum = Math.floor(deterministicRandom(seed + i + j) * 100000) + 1;

    while (Object.values(test).includes(doubleRandomNum)) {
      doubleRandomNum = Math.floor(deterministicRandom(doubleRandomNum) * 100000) + 1;
    }

    test[doubleChar] = doubleRandomNum;
  }
}

console.log(JSON.stringify(test{1}));

I tried things to debug it but i dont even know if its a bug or just loading because after 5 minutes, no results

VLAZ
  • 26,331
  • 9
  • 49
  • 67
  • Try debugging it: [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/q/25385173) – VLAZ Sep 02 '23 at 05:40
  • 2
    `JSON.stringify(test{1})` is not any javascript – Jaromanda X Sep 02 '23 at 05:45
  • 2
    I can just say that this is a slow algorithm. The more element you have in test the more time it spends inside the while loops. Also JS Sin works in radians not in degrees. Since radians have a quite small loop you will start repating values really soon with Math.floor. Best you could do is to rething the algorithm and thing what is it that you want to get out of it. – Marko Taht Sep 02 '23 at 05:49
  • Add some additional `console.log()` statements at key points in the code to track progress. – Tangentially Perpendicular Sep 02 '23 at 06:34

0 Answers0