整数で返るrand関数をさくっと作っておきましょう。
var rand = function(n){
return Math.floor(Math.random() * n) + 1;
};
こんなかんじで関数を定義して、下のように使います。
console.log(rand(100));
// -> 1~100のランダムな数が返る
More than 5 years have passed since last update.
整数で返るrand関数をさくっと作っておきましょう。
var rand = function(n){
return Math.floor(Math.random() * n) + 1;
};
こんなかんじで関数を定義して、下のように使います。
console.log(rand(100));
// -> 1~100のランダムな数が返る
Register as a new user and use Qiita more conveniently