- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在开发一个用 Objective-C 和 C++ 编写的 iOS 应用程序。在 C++ 部分,我需要加密安全随机数。
据我了解 iOS 安全模型,无法直接访问 /dev/random
。对吗?
获得安全随机数的官方方法是 SecRandomCopyBytes .遗憾的是,这是一个 Objective-C 接口(interface)。有没有一种方法可以从 C++ 使用这个接口(interface),最好不用求助于 Objective-C++?
还有 arc4random , 但我现在不愿意使用任何基于 RC4 的东西......
最佳答案
在任何基于“C”的语言(包括 Swift)上获取加密安全随机数的一种方法是“C”arc4random功能。
对于随机数整数 (u_int32_t),使用 arc4random()
和 arc4random_uniform()
。
对于一系列随机字节,使用 arc4random_buf()
函数用 ARC4 派生的随机数据填充长度为 nbytes 的缓冲区。
RC4是arc4random的一部分,关键是连续播种:
The arc4random() function provides a high quality 32-bit pseudo-random number very quickly. arc4random() seeds itself on a regular basis from the kernel strong random number subsystem described in random(4).
arc4random source code可用。请注意,它是通过(搅拌)部分地通过从 /dev/urandom
中读取来播种的。注意避免众所周知的 RC4 弱点。此外,初始化状态时包含时间,因此不可能两次重新生成相同的随机序列。
注意:虽然文档指出 /dev/random
会因熵不足而阻塞,但这在 OS X 上可能并非如此,它可能更像是 /dev/urandom
.
关于c++ - 在 iOS 上的 C++ 中获取加密安全随机数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32767935/
我编写了一个函数来随机从 [-10,10] 中获取一对。 import System.Random main = do { s State g a randomSt = S
好的,我了解如何在 Scala 中实现随机数生成器以及如何设置生成的随机数的上限,但我对如何更改下限感到困惑。例如: var computerGuess= scala.util.Random
我写了一个函数来从 [-10,10] 中随机得到一对。 import System.Random main = do { s State g a randomSt = St
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我正在做一个项目,我需要在其中生成 8 个随机数。由于某种原因,我遇到随机数部分非常耗时的问题。 8 个随机数的意思是我需要一个由数字 0-9 组成的 8 个字符长的字符串。例如 01234567 或
这个问题已经有答案了: Why do I always get the same sequence of random numbers with rand()? (12 个回答) 已关闭 9 年前。
我看到这个问题可能已经在这里得到回答:Random using WELL512 但是,它对用户不太友好,也没有提供如何在“真实世界”的代码片段中使用它的示例。 这是我目前拥有的: #define m
我想知道是否有人可以为我澄清这一行。 Create a function die(x) which rolls a die x times keeping track of how many time
我正在制作一款有 6 名防守球员的足球比赛。我将这段代码设置为随机让他们都向四分卫移动。 我想知道是否有更好的方法来做到这一点。我知道必须有一种方法可以在没有这么多 if 语句的情况下循环它,但我对
在以下位置:http://www.fredosaurus.com/notes-cpp/misc/random.html 它提到如果我们想生成一个1-10范围内的随机数,我们可以这样做: r = (ra
如何在 Linux 和 C++ 中使用随机数? 我找到了一些我想使用的代码,它有一行 srand((unsigned)time(0));//seed 但是 gcc 说 board.cpp:94:24:
这个问题在这里已经有了答案: Generating random whole numbers in JavaScript in a specific range (40 个答案) 关闭 9 年前。
我有以下脚本: Timer=0; function countdown(auctionid){ var auctions; var divs; Timer=Timer+1;
利用oracle的dbms_random包结合rownum来实现,示例如下,随机取499户: select * from ( select * from busi.t_ar_
我需要获取随机数,但它不应该等于之前的数字。这是我的一段代码。但这不起作用。 function getNumber(){ var min = 0; var max = 4; var i;
我对 Haskell 还很陌生。我有一个数据类型: data Sentence= Prop Int | No Sentence | And [Sentence]
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
这个问题已经有答案了: How do I generate random integers within a specific range in Java? (73 个回答) 已关闭 7 年前。
function getRandomArbitrary(min, max) { var r = Math.floor(Math.random() * (max - min + 1) + m
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Generate random number with non-uniform density 我尝试识别/
我是一名优秀的程序员,十分优秀!