美文网首页
随机函数

随机函数

作者: YuWenHaiBo | 来源:发表于2016-08-02 21:00 被阅读36次
The arc4random() function uses the key stream generator employed by the arc4 cipher, which uses 8*8 8
bit S-Boxes.  The S-Boxes can be in about (2**1700) states.  The arc4random() function returns pseudo-random pseudorandom
random numbers in the range of 0 to (2**32)-1, and therefore has twice the range of rand(3) and
random(3).

arc4random_buf() function fills the region buf of length nbytes with ARC4-derived random data.

arc4random_uniform() will return a uniformly distributed random number less than upper_bound.
arc4random_uniform() is recommended over constructions like     arc4random() % upper_bound'' as it avoids
"modulo bias" when the upper bound is not a power of two.

The arc4random_stir() function reads data from /dev/urandom and uses it to permute the S-Boxes via
arc4random_addrandom().

There is no need to call arc4random_stir() before using arc4random() functions family, since they auto-matically automatically
matically initialize themselves.

翻译: 具体翻译自己Google去,这里只说部分

Objective-C 中有个arc4random(函数用来生成随机数且不需要种子但是这个
函数生成的随机数范围比较大,需要用取模的算法对随机值进行限制,有点麻烦。  
其实Objective-C有个更方便的随机数函数arc4random_uniform(x),
可以用来产生0~(x-1)范围内的随机数,不需要再进行取模运算。
如果要生成1~x的随机数,可以这么写:arc4random_uniform(x)+1

本文参考链接:

https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/arc4random_uniform.3.html

相关文章

  • 均匀分布随机函数的实现

    前言 随机函数就是产生数的函数,C语言里使用rand(),srand()等随机函数实现随机数生成。 函数简介 in...

  • Jmeter——Dummy Sampler

    一、Dummy Sampler 二、随机函数生成当前时间 生成当前时间 三、随机函数生成数据 _Random随机函...

  • Python Random库的使用

    random库用于生成随机数 基本随机数函数: seed(), random() 扩展随机数函数: randint...

  • 2019-02-24

    2019-02-24 12.7 随机函数RAND函数和RANBETWEEN函数均能生成随机数RAND函数不需要参数...

  • 随机函数&当前时间戳函数

    随机函数 当前时间戳函数

  • Python函数

    数学函数 随机数函数

  • 随机函数

    rand()函数只能生成0到1之间的随机小数,如果想要生成0到10,0到100就rand()相应的值。如果想得到整...

  • 随机函数

    翻译: 具体翻译自己Google去,这里只说部分 本文参考链接: https://developer.apple....

  • VRF-可验证随机函数

    VRF-可验证随机函数   VRF(Verifiable Random Function):可验证随机函数用于区块...

  • SQL随机生成姓名、手机号、字符串等

    补充 关于sql中rand()函数的使用 1、随机生成姓名(函数的形式) 调用函数 2、随机生成手机号 调用函数 ...

网友评论

      本文标题:随机函数

      本文链接:https://www.haomeiwen.com/subject/anfqsttx.html