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

151
Views
El generador de números aleatorios sigue dando cero cuando se dan el mínimo y el máximo
var prevRandomNum = -1; var arr=[]; var math=[]; window.onload=function(){ var ref = firebase.database().ref("manga"); ref.once("value", function(snapshot) { snapshot.forEach(function(childSnapshot) { var childKey = childSnapshot.key; arr.push(childKey); }); }); } function g(){ const btn = document.getElementById("btng"); btn.innerText = "Suggest me another"; var sorry="im/sorry.png"; console.log(arr.length); var randomNum; var calc=arr.length-1; if(math.length==calc){ document.getElementById("mname").textContent= "Sorry you have reached the end of the manga list i have suggested."; document.getElementById("mgenre").textContent= "I will be uploading new suggestions soon."; document.getElementById("mchap").textContent= ""; document.getElementById("mstatus").textContent= ""; document.getElementById("img").src=sorry; document.getElementById("pic").style.backgroundImage=`url(${sorry})`; } else{ do{ randomNum= Math.floor(Math.random() * (arr.length-1) )+1; console.log("rand "+ randomNum); }while(randomNum=== prevRandomNum||math.includes(randomNum)); prevRandomNum = randomNum; math.push(prevRandomNum); }

Arriba está el código que estoy usando para recuperar datos de la base de datos de firebase y obtener el valor de un nodo principal específico usando un número aleatorio, he almacenado la tecla de inserción en una matriz y estoy usando un generador de números aleatorios para obtener datos principales únicos y aleatorios cada vez que se presiona el botón pero el azar da 0 como número aleatorio incluso cuando se da el número mínimo y máximo. Puede consultar la vista previa en vivo aquí https://kazemanga.xyz/ , abra la consola para ver si el número aleatorio es cero o no. Cualquier ayuda sería apreciada.

arr.length = 7 (el número del nodo principal en la base de datos es 7) Es posible que no dé un no aleatorio como Cero en el primer clic, así que actualice e intente nuevamente, no da cero a veces y cuando actualizo la página y lo intento de nuevo me da

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!