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

241
Views
Generar nuevos valores aleatorios y almacenarlos en una matriz

Estoy tratando de generar dos valores aleatorios y almacenarlos en una matriz; sin embargo, me gustaría que fueran valores diferentes cada vez que se genera un número aleatorio entre 0 y 3.

 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));

¿Cómo edito esta función en la que, si se inserta una matriz de los mismos números en la matriz1, se eliminan y se generan 10 coordenadas únicas? La ayuda será apreciada, gracias

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

0

Según la pregunta de Sam en los comentarios, aquí está el código:

 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 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!