实现rand() [英] implementation of rand()

查看:145
本文介绍了实现rand()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在C中编写一些嵌入式代码,需要使用rand()函数。不幸的是,控制器的库中不支持rand()。我需要一个快速的简单实现,但更重要的是几乎没有空间开销,产生较高质量的随机数。有没有人知道使用哪个算法或代码?



编辑:这是为了图像处理,所以相对较高的质量意味着体面的循环长度和良好的均匀性。 p>

解决方案

查看这个随机数生成器的集合。他是随机数生成的领先专家,所以我有信心使用他推荐的任何东西。该清单中的发电机很小,有些只需要几个无符号的长度作为状态。



Marsaglia的发电机绝对是高品质,您的标准长期和良好的制服分配。他们通过严格的统计测试,尽管它们不会用于加密。


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?

EDIT: 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.

这篇关于实现rand()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆