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

267
Views
Números aleatorios en el rango No aleatorio

Traté de generar números aleatorios entre 1 y 10 millones, pero descubrí que ninguno de los números generados era inferior a 1 millón. Escribí este código para probar el problema. Este código selecciona diez millones de números aleatorios entre 1 y diez millones y genera el número más bajo. Esperaría obtener al menos algo en el rango de 100-1000 al menos, pero siempre es al menos 1 millón. ¿Qué me he perdido?

JSFiddle: https://jsfiddle.net/vhLoqz8g/

 var lowest=10000000; for (let i = 0; i < 10000000; i++) { var g=Math.floor(Math.random() * (10000000 - 1 + 1)) + 1; if (g<lowest) { lowest=g; } } document.write(g);

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe generar la salida lowest y no g al final de su bucle:

 var lowest=1e8; for (let i = 0; i < 1e7; i++) { var g=Math.floor(Math.random()* 1e7) + 1; if (g<lowest) lowest=g; } console.log(lowest)

about 4 years ago · Juan Pablo Isaza Report
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!