I get negative numbers from arc4random, so I have to use abs(arc4random()) in my result which obviously defeats some randomness. Why??? I thought the range was within 0..INT_MAX not INT_MIN...INT_MAX.
for( int j=0; j<10; j++ ){
int r = arc4random();
NSLog(@"%s \t%d \t%d \t%d", (r>=0) ? "++++" : "----", j, r, r % 10);
}
assert(0);
generates the following output:
2009-10-17 11:15:22.737 Fortune[1281:207] ++++ 0 987748783 3
2009-10-17 11:15:22.758 Fortune[1281:207] ---- 1 -81091275 -5
2009-10-17 11:15:22.771 Fortune[1281:207] ++++ 2 98279690 0
2009-10-17 11:15:22.784 Fortune[1281:207] ---- 3 -694992398 -8
2009-10-17 11:15:22.796 Fortune[1281:207] ++++ 4 1467322001 1
2009-10-17 11:15:22.808 Fortune[1281:207] ++++ 5 1282335903 3
2009-10-17 11:15:22.820 Fortune[1281:207] ---- 6 -379255192 -2
2009-10-17 11:15:22.832 Fortune[1281:207] ++++ 7 202687027 7
2009-10-17 11:15:22.841 Fortune[1281:207] ---- 8 -1099161751 -1
2009-10-17 11:15:22.850 Fortune[1281:207] ++++ 9 2105903055 5