0

I want to generate a random double ending with .0 or .5. I tried using Math.floor(Math.random() * (10 + 1)); and still giving me only the ones ending with .0. how could I solve this?

Mike 'Pomax' Kamermans
  • 44,582
  • 14
  • 95
  • 135
were
  • 43
  • 4
  • `Math.floor` rounds down to a whole number, so if you don't want things to end in `.0`, don't round down as your last step? First describe what you need in terms of numbers you can generate. For example, a random number ending in .0 or .5 is the same as "some even or odd whole number, divided by two". – Mike 'Pomax' Kamermans Feb 16 '22 at 05:54

0 Answers0