9

I've been reading through some code and noticed a function:

    randint: function(n) {
        return ~~(Math.random() * n)
    }

I know ~ means "not" but how does ~~ change this return statement?

Orane
  • 1,909
  • 1
  • 18
  • 29

1 Answers1

16

"but how does ~~ change this return statement?"

Answer: It cuts all fractional digits.

~~42.453754 -> 42

tmuecksch
  • 5,045
  • 3
  • 33
  • 55