zoukankan      html  css  js  c++  java
  • 超快速梅森旋转SFMT(SIMD-oriented Fast Mersenne Twister)一览

    众所周知mt19937能够快速产生高质量伪随机数,可以随便跑个1e8次。
    但是如果需要大量随机数mt19937的速度就跟不上了。
    最近无意间翻到了一个gnu私货sfmt19937,其定义在ext/random中,速度极快。
    以下是测试代码及其耗时。

    #include <cstdio>
    #include <cmath>
    #include <ctime>
    #include <algorithm>
    #include <ext/random>
    #define _A
    #ifdef _A
    __gnu_cxx::sfmt19937 rnd(114);
    #endif
    #ifdef _B
    std::mt19937 rnd(114);
    #endif
    #ifdef _C
    inline int rnd(void)
    {
    	static unsigned x=114;
    	return x=(x*998244353+19198001);
    }
    #endif
    unsigned int tmp;
    int main()
    {
    	for(int i=1; i<=1e9; ++i)
    	{
    		tmp+=rnd();
    	}
    	printf("%u
    ", tmp);
    	return 0;
    }
    

    经测试,mt19937耗时2.8s,线性同余耗时1.2s,而sfmt19937仅耗时0.8s

  • 相关阅读:
    后渗透
    Msf小结
    安全狗文件绕过
    文件上传漏洞
    SQL Injection(Blind)
    SQL Injection
    Linux 基础整理
    Python pip升级及升级失败解决方案
    文件包含
    信息收集
  • 原文地址:https://www.cnblogs.com/ynycoding/p/15499823.html
Copyright © 2011-2022 走看看