<span id="Label3"><p>Generates a random positive integer between 0-x</p><p></p><p>int value =arc4random_uniform (x + 1);</p><p>Generate Random positive integers</p><p>int value = Arc4random ()</p><p></p><p>The code for obtaining an integer between 0 and x-1 by Arc4random () is as Follows:</p><p>int value = Arc4random ()% x;</p><p></p><p>The code to get an integer between 1 and X is as Follows:</p><p>int value = (arc4random ()% x) + 1;</p><p></p><p>finally, if you want to generate a floating-point number, you can define the following macro in your project:</p><p>#define ARC4RANDOM_MAX 0x100000000</p><p></p><p>You can then use Arc4random () to get a floating-point number between 0 and 100 (the precision is twice times that of Rand ()), the code is as Follows:</p><p>Double val = Floorf ((double) arc4random ()/arc4random_max) * 100.0f);</p><p></p><p>Remark: If there is any mistake, please point out the big points, thank you!</p><p>Generate random number method in iOS</p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service