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

208
Vistas
(node) How do I get random values when an api is hit with a get request?

I am trying to get a random word when the endpoint '/randomword' is hit. I used Math.random to get a random number between the array index numbers- and try to get a random word by accessing an element with a random index. This code does give me a random word at first but it doesn't change with each get request.

I wrote this and it does return a random word but it doesn't change with each get request.

   rInt = getRandomInt(2)

   function getRandomInt(max) {return Math.floor(Math.random() * max);}

    wordList  = [
    {"word": "abase",
     "type": "verb",
     "meaning": "lower in position; degrade"},

     {"word": "abbess",
      "type": "verb", 
       "meaning": "lady superior of a nunnery"},
  
     {"word": "abbot", 
      "type": "noun",
      "meaning": "head of monks"}
    ]

    randomWord = wordList[rInt];//console.log(randomWord);

    app.get('/randomword', function (req, res) {res.status(200).send(randomword)})
about 4 years ago · Juan Pablo Isaza
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