Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
¿Por qué mi algoritmo repite valores en lugar de producir 32 valores únicos?

He hecho una pregunta similar antes: ¿Cómo hacer que este PRNG genere números dentro del rango?

¿Cómo tomo eso y lo hago funcionar para un número que puede tener hasta 5 bits (32 valores posibles)? Intenté esto pero está dando valores "no válidos":

 const fetch = (x, o) => { if (x >= o) { return x } else { const v = (x * x) % o return (x <= o / 2) ? v : o - v } } const fetch16 = (x) => fetch(x, 65519) const fetch8 = (x) => fetch(x, 251) // the last number can be anything. // MODIFIED THIS const build32 = (x, o) => fetch8((fetch8(x) + o) % 256 ^ 101) % 32 const j = 115; // If you don't want duplicates, either i or j should stay fixed let i = 0 let invalid = []; let valid = new Set; while (i <= 32) { // <-- small fix here! let x = build32(i, j); // To test, you can swap i and j here, and run again. if (x > 31 || valid.has(x)) { invalid.push([i, j, x]); } else { valid.add(x); } i++; } console.log("invalid:", invalid); console.log("valid:", [...valid]); console.log("count of valid:", valid.size);

El sistema debe iterar a través de los números 0-31 sin repetir, en lo que parece un orden aleatorio.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!