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

136
Views
how to generate two numbers between 0 and 4 in javascript, but make sure the numbers aren't the same

I'm trying to generate two numbers between 0 and 4 in javascript, but I don't want the two numbers to be the same. Any thoughts?

currently working with

state.blue_id = Math.floor(Math.random()*5);
state.red_id = Math.floor(Math.random()*5);
if(state.blue_id == state.red_id){
        ???????
    }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Have you considered using while?

while (state.blue_id === state.red_id) {
    state.blue_id = Math.floor(Math.random()*5);
    state.red_id = Math.floor(Math.random()*5);
}
about 4 years ago · Juan Pablo Isaza Report

0

"Rejection" is the standard way to handle this:

state.blue_id = Math.floor(Math.random()*5);
state.red_id = Math.floor(Math.random()*5);
while(state.blue_id == state.red_id){
        state.red_id = Math.floor(Math.random()*5);
    }

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!