乱数の作り方

0 ~ 1

Math.random()を使用すると0~1の数が得られる。

const num = Math.ramdom()

0 ~ 100

これは100を掛けたあと、四捨五入して+1するとできる

const num = Math.floor(Math.random() * 100) + 1;

-100 ~ 100

これは201倍した後-100する。
なぜ201なのかは-200-1100個、1200100個、0が一個あるから
100+100+1 = 201である。

const num = (Math.floor(Math.ramdom() * 201)) - 100;