实施兰特() [英] implementation of rand()
问题描述
我写一些C嵌入式code和需要使用rand()函数。不幸的是,兰特(),在控制器的库不支持。我需要一个简单的实现,是快速的,但更重要的是有一点空间开销,产生相对高质量的随机数。有谁知道要使用的算法或样品code?
I am writing some embedded code in C and need to use the rand() function. Unfortunately, rand() is not supported in the library for the controller. I need a simple implementation that is fast, but more importantly has little space overhead, that produces relatively high-quality random numbers. Does anyone know which algorithm to use or sample code?
编辑:这是图像处理,所以质量相对较高是指体面的周期长度和良好的均匀性
It's for image processing, so "relatively high quality" means decent cycle length and good uniform properties.
推荐答案
看看这个集合数发生器乔治马尔萨利亚的。他在随机数生成的权威专家,所以我会用什么,他建议有信心。在该列表中的发电机是微小的,一些只需要一对夫妇的无符号多头的状态。
Check out this collection of random number generators from George Marsaglia. He's a leading expert in random number generation, so I'd be confident using anything he recommends. The generators in that list are tiny, some requiring only a couple unsigned longs as state.
马尔萨利亚的发电机绝对是高品质你的长期和良好的均匀分布的标准。他们通过严格的统计测试,但他们不会为加密做的。
Marsaglia's generators are definitely "high quality" by your standards of long period and good uniform distribution. They pass stringent statistical tests, though they wouldn't do for cryptography.
这篇关于实施兰特()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!