I need to randomly generate either a "-1" or a "1" to determine the sign of a number randomly... What's the shortest method? I am currently using this but it seems pretty long:
sign = (round((arc4random() % 2)))-((round((arc4random() % 2))) == 0);
What about arc4random_uniform(2) ? -1 : 1
?
or arc4random_uniform(2)*2 - 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With