比兰特()更快? [英] Faster than rand()?

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

问题描述

我的工作,需要以尽可能快的产生数百万数的算法。其实我发现我的算法兰特()函数的处理时间的75%。

所以我在寻找的东西更快。而且我也不需要一个大的范围内的。 (我只需要低于1000整数)

你知道的东西,我可以使用?

谢谢!

编辑:

我用这个号码洗牌小于1000的实体组。

我发现了更多关于快兰特。并有SSE版本版本,这是更快,同时产生4个号码。

<一个href=\"https://software.intel.com/en-us/articles/fast-random-number-generator-on-the-intel-pentiumr-4-processor/\" rel=\"nofollow\">https://software.intel.com/en-us/articles/fast-random-number-generator-on-the-intel-pentiumr-4-processor/


解决方案

 静态unsigned int类型g_seed;//用于种子发电机。
内嵌无效fast_srand(INT种子)
{
        g_seed =种子;}// fastrand例程返回一个正整数,相似的输出值范围为C库。内联INT fastrand(){g_seed =(214013 * g_seed + 2531011);  回报(g_seed&GT;&GT; 16)及0x7FFF的;}

I'm working on an algorithm which needs to generate millions of numbers as fast as possible. Actually I found out that the rand() function of my algorithm takes 75% of the process time.

So I'm looking for something faster. And I don't need a big range at all. (I only need integer numbers below 1000)

Do you know something I could use ?

Thanks !

Edit :

I use this numbers for shuffling groups of less than 1000 entities.

I found out more about the "fast rand". And there is SSE version version which is even faster and generates 4 numbers at a time.

https://software.intel.com/en-us/articles/fast-random-number-generator-on-the-intel-pentiumr-4-processor/

解决方案

static unsigned int g_seed;

//Used to seed the generator.           
inline void fast_srand( int seed )   
{
        g_seed = seed;

}

//fastrand routine returns one integer, similar output value range as C lib.

inline int fastrand()

{

g_seed = (214013*g_seed+2531011);

  return (g_seed>>16)&0x7FFF;

}

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

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