Speed up random number generation in MATLAB

后端 未结 3 1831
离开以前
离开以前 2021-01-15 06:15

Is there any way to generate pseudo-random numbers to less precision and thus speed the process up?

Another thing is that I know it saves time if random numbers are

3条回答
  •  隐瞒了意图╮
    2021-01-15 06:28

    Since R2015a the rng function for configuring and seeding the global generator has a 'simdTwister' option that uses a faster "SIMD-oriented Fast Mersenne Twister" algorithm:

    rng(1,'twister');
    R = rand(1e4); % Warmup for timing
    tic
    R = rand(1e4);
    toc
    
    rng(1,'simdTwister');
    R = rand(1e4); % Warmup for timing
    tic
    R = rand(1e4);
    toc
    

    This will probably be the fastest builtin generator for your system (excepting the possibility of GPU-based generators). On my computer it's a little more than twice as fast as the default Mersenne Twister algorithm for large arrays.

提交回复
热议问题