1
0

More than 1 year has passed since last update.

randメソッド

Last updated at Posted at 2022-11-16

はじめに

乱数の実装をする際に必要な知識を忘れないために記録に残す

randメソッド

randメソッドで乱数を実装することができます。

# 使い方
rand(欲しい乱数の数)
randメソッドを使うと手軽に乱数を生成できます。randメソッドに引数として数を渡すと「0」から「渡した数 - 1」の間でランダムに数を返します。

rand(100) # => 0〜99の中から1つ整数をランダムに返す

rand(1..5) # => 1~5の中の整数を返す
1
0
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
1
0