{"id":556,"date":"2023-02-25T19:01:22","date_gmt":"2023-02-25T11:01:22","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=556"},"modified":"2023-04-29T20:36:45","modified_gmt":"2023-04-29T12:36:45","slug":"swift-use-arc4random-arc4random-uniform-get-random-numbers","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/swift-use-arc4random-arc4random-uniform-get-random-numbers\/","title":{"rendered":"Swift &#8211; \u4f7f\u7528arc4random()\u3001arc4random_uniform()\u83b7\u53d6\u968f\u673a\u6570"},"content":{"rendered":"<p><code>arc4random()<\/code> \u8fd9\u4e2a\u5168\u5c40\u51fd\u6570\u4f1a\u751f\u621010\u4f4d\u6570\u7684\u968f\u673a\u6574\u6570\uff08UInt32\uff09\u3002\u5176\u751f\u6210\u7684\u6700\u5927\u503c\u662f4294967295\uff082^32 &#8211; 1\uff09\uff0c\u6700\u5c0f\u503c\u4e3a0\u3002<\/p>\n<p>\uff081\uff09\u4f7f\u7528 <code>arc4random<\/code> \u51fd\u6570\u6c42\u4e00\u4e2a 1~100 \u7684\u968f\u673a\u6570\uff08\u5305\u62ec1\u548c100\uff09<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-swift\">let temp = Int(arc4random()%100)+1<\/code><\/pre>\n<p>\uff082\uff09\u4f7f\u7528 <code>arc4random_uniform<\/code> \u51fd\u6570\u6c42\u4e00\u4e2a 1~100 \u7684\u968f\u673a\u6570\uff08\u5305\u62ec1\u548c100\uff09<\/p>\n<pre><code class=\"language-swift\">let temp = Int(arc4random_uniform(100))+1<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>arc4random() \u8fd9\u4e2a\u5168\u5c40\u51fd\u6570\u4f1a\u751f\u621010\u4f4d\u6570\u7684\u968f\u673a\u6574\u6570\uff08UInt32\uff09\u3002\u5176\u751f\u6210\u7684\u6700\u5927\u503c\u662f4294967 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[171],"tags":[],"class_list":["post-556","post","type-post","status-publish","format-standard","hentry","category-swift"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/556","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=556"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/556\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}