Objective-C 中有个arc4random()函数用来生成随机数且不需要种子,但是这个函数生成的随机数范围比较大,需要用取模的算法对随机值进行限制,有点麻烦。

其实Objective-C有个更方便的随机数函数arc4random_uniform(x),可以用来产生0~(x-1)范围内的随机数,不需要再进行取模运算。如果要生成1~x的随机数,可以这么写:arc4random_uniform(x)+1。

arc4random和arc4random_uniform的更多相关文章

  1. Swift - 使用arc4random()、arc4random_uniform()取得随机数

    arc4random()这个全局函数会生成9位数的随机整数   1,下面是使用arc4random函数求一个1~100的随机数(包括1和100) 1 var temp:Int = Int(arc4ra ...

  2. stdlib标准库的常用API

    iOS 有如下四种随机数方法,下面以产生 [0,100) 的随机数为例: 1. srand((unsigned)time(0));  //不加这句每次产生的随机数不变 int i = rand() % ...

  3. rand & random & arc4random

    rand(3) / random(3) / arc4random(3) / et al. Written by Mattt Thompson on August 12th, 2013 What pas ...

  4. iOS--九宫格奥秘(UIView)(arc4random)

    下面程序主要实现,九宫格的模型,每个小UIView的颜色随机产生的,用到了 arc4random函数: ; ; ; ; ; i<; i++) { ; j<; j++) { UIView * ...

  5. objective-c 中随机数的用法 3种:arc4random() 、random()、CCRANDOM_0_1()

    oc 中随机数的用法(arc4random() .random().CCRANDOM_0_1() 1).arc4random() 比较精确不需要生成随即种子 使用方法 : 通过arc4random() ...

  6. oc 中随机数的用法(arc4random( ) 、random( )、CCRANDOM_0_1( )

    来源:http://www.cnblogs.com/jay-dong/archive/2012/07/23/2604916.html 1).arc4random() 比较精确不需要生成随即种子 使用方 ...

  7. objective-c 中随机数的用法 (3种:arc4random() 、random()、CCRANDOM_0_1() )

    1.随机数的使用      1).arc4random() 比较精确不需要生成随即种子 使用方法 : 通过arc4random() 获取0到x-1之间的整数的代码如下: int value = arc ...

  8. iPhone开发随想:rand()还是arc4random()

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://bj007.blog.51cto.com/1701577/544006 今天在iP ...

  9. 【iOS】arc4random() 产生随机数

    通过 arc4random() 获取 0 到 x-1 之间的整数的代码如下: int value = arc4random() % x; 获取 1 到 x 之间的整数的代码如下: ; PS: 这里用到 ...

随机推荐

  1. OD: Windows Driver Fuzz

    内核 FUZZ 思路 内核 API  函数:是提供给 Ring3 调用,在 Ring0 完成最终功能的函数.这些函数接收 Ring3 传入的参数,如果处理参数的过程存在问题的话,很有可能成为一个内核漏 ...

  2. MySQL+PHP配置 Windows系统IIS版(转)

    1.下载 MySQL下载地址:http://dev.mysql.com/downloads/mysql/5.1.html->Windows (x86, 32-bit), MSI Installe ...

  3. Python 函数的使用 外加引入文件

    #coding=utf-8 #!user/bin/python import sys import test2 def functionsss(name,sex,age=25): print name ...

  4. photoshop mac版下载及破解

    1.下载 直接百度photoshop,就可以找到百度的下载源: 2.破解 http://zhidao.baidu.com/question/581955095.html

  5. c# 使用递归 循环遍历导航树结构 并解析

    1.数据书库结构 1 家用电器 0 一级菜单 2 手机.数码.京东通信 0 一级菜单 3 电脑.办公 0 一级菜单 4 家具.家居.厨房 0 一级菜单 5 男装.女装.童装.内衣 0 一级菜单 6 个 ...

  6. JavaScript--函数-按值传递

    按值传递(byValue): 两个变量间赋值或将变量作为参数传入函数时,其实都是将原变量中的值,赋值一份给对方(新变量) 对原始类型的值: 修改新变量,不会影响原变量 对引用类型的对象: 通过新变量修 ...

  7. FingerChaser(3) 解题报告目录

    所有代码都不超过40行... A:http://www.cppblog.com/willing/archive/2010/05/04/114304.html B:http://www.cnblogs. ...

  8. WebService cxf 接口中获得拦截器参数

    1. 拦截器中put属性 Message message = PhaseInterceptorChain.getCurrentMessage(); message.put("AuthCode ...

  9. jQuery1.6以上版本prop和attr的区别

  10. jquery easy ui 学习 (2) customtools window

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...