Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

293
Vistas
Generate a random number without repeating a previous number

I need to generate a random number without repeating a previous number. This is my code:

getRandomInt( max:number, min:number ) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

It gives me the generated random number but keeps repeating the same number.

Example:

1,2,3,4,4 

and in the second call:

1,12,3,14,15
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could easely do this:

Object.defineProperty(Array.prototype, 'shuffle', {
    value: function() {
        for (let i = this.length - 1; i > 0; i--) {
            const j = Math.floor(Math.random() * (i + 1))
            [this[i], this[j]] = [this[j], this[i]]
        }
        return this
    }
})
var numArray = Array.from(Array(10).keys()) //generate an array with number from 0 to 10
numArray.shuffle()

the .shuffle() method will randomly take one at a time off the array and print it out.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda