I'm afraid arc4random betrayed me

I have a code that creates a random number from 0 to 1. I see that the number 1 fits much more times than the number 0, then I think it will be statistically possible.

This is my code:

int shipNumber = arc4random() % 2; 

Should this code work? Am I just losing my mind?

+6
source share
2 answers

This code should work.

What I suspect you see is really random (or at least random enough) and your brain is trying to find patterns. (Every brain tries to find patterns everywhere. This is how you read it. The problem is that in chance there is (which is largely determined) for your brain to snap it, so it invents some of them.)

If you really want to check your result for chance, you will need to do some kind of statistical analysis.

+5
source

Perhaps you see the error modulo .

0
source

Source: https://habr.com/ru/post/889816/


All Articles