-8

I am trying to write a couple of statements that chooses either 0 or 1

and I want 0 and 1 to have the equal possibilities

I did this

chosendirection = Math.floor(Math.random()*2);

but the above does not choose 0. It chooses 1 only.

Thanks!

1 Answers1

0

Math.round(Math.random())

Math.random already returns a value between 0 and 1

Michael Benjamin
  • 2,895
  • 1
  • 16
  • 18