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

245
Vistas
Generate new random values and store in an array

I am trying to generate two random values and store them in an array however I would like them to be different values each time a random number between 0-3 is generated.

function new_Randomvalues(n) {
    var array1 = [];
    for (var i = 0; i < n; i++) {
        var row = Math.round(3*Math.random());
        var col = Math.round(3*Math.random());
        array1.push([row,col]);
    }
    return array1;
}
console.log(new_Randomvalues(10));

How do I edit this function where if an array of same numbers are pushed into array1 then remove those and generate 10 unique coordinates. Help would be appreciated thanks

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Per sam's question in the comments, here's the code:

function shuffle(array) {
    for (var i = array.length - 1; i > 0; i--) {
        var j = Math.floor(Math.random() * (i + 1));
        var temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
}

pairs = [];

for (let i = 0; i <= 3; i++) {
    for (let j = 0; j <= 3; j++) {
        pairs.push([i, j]);
    }
}

shuffle(pairs);

pairs = pairs.slice(0, 10);

console.log(pairs);

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