⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 r4_uniform_01.m

📁 用于生成一个正态分布的伪随机数数值序列
💻 M
字号:
function [ r, seed ] = r4_uniform_01 ( seed )%% R4_UNIFORM_01 returns a unit pseudorandom R4.%%  Discussion:%%    This routine implements the recursion%%      seed = 16807 * seed mod ( 2**31 - 1 )%      r = seed / ( 2**31 - 1 )%%    The integer arithmetic never requires more than 32 bits,%    including a sign bit.%%    If the initial seed is 12345, then the first three computations are%%      Input     Output      R4_UNIFORM_01%      SEED      SEED%%         12345   207482415  0.096616%     207482415  1790989824  0.833995%    1790989824  2035175616  0.947702%%  Author:%%    John Burkardt%%  Modified:%%    14 November 2004%%  Reference:%%    Paul Bratley, Bennett Fox, Linus Schrage,%    A Guide to Simulation,%    Springer Verlag, pages 201-202, 1983.%%    Pierre L'Ecuyer,%    Random Number Generation,%    in Handbook of Simulation,%    edited by Jerry Banks,%    Wiley Interscience, page 95, 1998.%%    Bennett Fox,%    Algorithm 647:%    Implementation and Relative Efficiency of Quasirandom%    Sequence Generators,%    ACM Transactions on Mathematical Software,%    Volume 12, Number 4, pages 362-376, 1986.%%    Peter Lewis, Allen Goodman, James Miller,%    A Pseudo-Random Number Generator for the System/360,%    IBM Systems Journal,%    Volume 8, pages 136-143, 1969.%%  Parameters:%%    Input, integer SEED, the integer "seed" used to generate%    the output random number.  SEED should not be 0.%%    Output, real R, a random value between 0 and 1.%%    Output, integer SEED, the updated seed.  This would%    normally be used as the input seed on the next call.%  seed = floor ( seed );  seed = mod ( seed, 2147483647 );  if ( seed < 0 )     seed = seed + 2147483647;  end   k = floor ( seed / 127773 );  seed = 16807 * ( seed - k * 127773 ) - k * 2836;  if ( seed < 0 )    seed = seed + 2147483647;  end  r = single ( seed * 4.656612875E-10 );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -