13
16

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 5 years have passed since last update.

Swift備忘録  乱数を取得する関数

Last updated at Posted at 2015-01-20

Swiftで乱数を取得する関数は以下の3つ

  rand
  arc4random
  arc4random_uniform

arc4randomとarc4random_uniformの関係は、以下のようになっており、
arc4random_uniformはモジュロバイアスの影響は受けません。
  
  arc4random() % upper_bound
  arc4random_uniform(upper_bound)

7桁までの乱数を取得したい場合は、arc4random_uniform(10000000)とすると
0〜9999999までの乱数を取得することができます

13
16
2

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
13
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?