0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JavaScriptで範囲指定乱数生成

Last updated at Posted at 2021-06-06

#はじめに
JavaScript(TypeScript)で乱数を作る時、いつも迷うのでここにメモしておく

やりたいこと

最小値(min)以上、最大値(max)以下の乱数を取得する。

random.js
const rand = (min, max) => {
  return (Math.floor(Math.random() * (max - min + 1)) + min);
};
random.ts
const rand = (min: number, max: number): number => {
  return (Math.floor(Math.random() * (max - min + 1)) + min);
};
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?