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

164
Views
Genera un entero aleatorio redondeado al número entero más cercano

Me pregunto cómo generar un número entero aleatorio que se redondee al número entero más cercano, por ejemplo, un número aleatorio: 436, == 440 o 521, == 520. Básicamente, solo redondeo el número aleatorio al número entero más cercano. (JavaScript)

 Math.floor(Math.random() * max) + min; //gets random number //then I want to round the number here, maybe even in the same line as where the number is //being generated.
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Creo que esto debería hacer el trabajo:

 result = Math.round((Math.floor(Math.random() * max) + min) / 10) * 10;
about 4 years ago · Juan Pablo Isaza Report

0

Para redondear un número, puede usar Math.floor(n / 10) * 10 . Ejemplo:

 function randomRoundNumber(min, max) { return Math.round((Math.floor(Math.random() * (max - min)) + min) / 10) * 10; }
 <button onclick="console.log(randomRoundNumber(parseInt(prompt('min?')),parseInt(prompt('max?'))))">Random number</button>

about 4 years ago · Juan Pablo Isaza Report

0

Esto debería hacer el trabajo

 Math.round((Math.floor(Math.random() * max) + min) / 10) * 10
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!