问题描述
我下载isaac64从和我有一些问题与使用情况。
我不得不发表评论code的一部分在isaac64.c becouse它包含了主要的功能。但我不能用它......我不能正确初始化,并得到随机数,你能帮帮我吗?我couldn'y发现的例子。
I downloaded isaac64 from here and I have some problem with usage.I had to comment a part of code in isaac64.c becouse it contained main function. But I can't use it... I can't properly initialize it and get random number, can you help me? I couldn'y found any example.
randinit(TRUE);
for(i=0;i<10;i++){
printf("%lx\n",rand());
}
我每次运行此code时,我得到了相同的值。我不知道如何设置种子。
each time I run this code I get the same values. I don't know how to set seed.
推荐答案
这以撒的版本是参考实现,这意味着它的意图被称为,但不是特别用户友好的或准备投产。有任何数目的加密安全随机数发生器的在C,它更容易使用。特别是,简单的读从字节是在大多数操作系统上不够好
This version of ISAAC is a "reference implementation" meaning it's intended to be referred to but isn't particularly user friendly or ready for production. There are any number of cryptographically secure random number generators in C that are easier to use. In particular, simply reading bytes from /dev/random is good enough on most operating systems.
的主
函数演示如何使用图书馆。它已经与 #IFDEF
取值注释掉。我发现也有帮助。
The main
function demonstrates how to use the library. It's already commented out with #ifdef
s. I've found using the Perl wrapper around ISAAC as a guide also helps.
int main()
{
/* Initialize the structure to 0 */
randctx ctx;
ctx.randa = ctx.randb = ctx.randc = (ub4)0;
/* Initialize the seed */
for (ub4 i=0; i<256; ++i) {
ctx.randrsl[i] = i;
}
/* Initialize the random numbers from the seed */
randinit(&ctx, TRUE);
/* Print 10 pseudo random numbers */
for(int i=0; i<10; i++) {
printf("%.8lx\n", rand(&ctx));
}
}
您必须提供种子
或。如果提供了相同的种子,你会得到相同的结果。这就是为什么ISAAC是的伪的随机数生成器,它只能使更多的随机数字似乎从现有的随意性。有
You must supply the seed
, or "entropy". If you supply the same seed you will get the same result. This is why ISAAC is a psuedo random number generator, it can only make more random-seeming numbers out of existing randomness. There is a discussion of where to get your seed from in Math::Random::ISAAC.
如果这是你新的概念,如果这个生产code,我的强烈建议您只需从的/ dev /随机读
。这ISAAC实现是非常粗糙,密码学的很容易的得到错误的。 的/ dev /随机
已照顾所有这一切都为你。
If these are new concepts to you, and if this for production code, I would strongly recommend you simply read from /dev/random
. This ISAAC implementation is very rough and cryptography is very easy to get wrong. /dev/random
has already taken care of all of this for you.
如果你必须使用自己的伪随机库,使用公实施和记录库类似的。
If you must use your own pseudo-random library, use a well-implemented and documented library like OpenSSL.
如果你打算用这个经历,我会建议调整的因为至少笔者已经清理它被释放值得的。
If you're going to go through with this, I would recommend adapting the version of the code from the Perl wrapper because at least the author has cleaned it up to be release worthy.
这篇关于如何使用ISAAC用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!