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

292
Views
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 answers
Answer question

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