質問

I am using arc4random() %2 in my code. It is called by 3 classes upon initialization, which happens in quick succession. However, approximately 70% plus of the results are always either all 0 or all 1 (the distribution between the 2 sets of 000 or 111 seems average). I would have expected a fairly random distribution of 1 and 0 between the 3 classes. How can this be explained?

役に立ちましたか?

解決

Although I cannot say this definitively, it does appear to be a seeding "issue". Calling arc4random() multiple times within milliseconds of each other will have a very high bias towards certain numbers. acr4random_uniform seems to solve this problem - seemingly it is seeded in a more "robust" manner

他のヒント

Use acr4random_unform(3) to avoid modulo bias

Read This Article:- http://nshipster.com/random/

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top