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

206
Views
(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
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!