2
0

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.

Goで乱数を発生させる

Last updated at Posted at 2020-06-18

##Goで乱数を発生させる方法

  • randパッケージを使う
  • rand.Seed()を設定する
  • rand.Intn()で範囲を指定する

##気を付けるポイント

  • rand.Seed()の値が固定されていると、rand.Intn()で表示される値は不変。
  • rand.Seed()を rand.Seed(time.Now().UnixNano()) などとして常に変化するようにする。
  • 変数にrand.Intn(n)を追加。これによって表示される値は 0<=i && i <n

##参考ページ
rand - Go 言語
サンプルで学ぶ Go 言語:Rand

2
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?