Matlab Math
Cleve Morler著
陈文斌( wbchen@fudan.edu.cn)
复旦大学 2002
随机数
Pseudorandom Number
format long; rand
0.95012928514718
pseudorandom number:
A random sequence is a vague notion …,in which each term
is unpredictable to the uninitiated and whose digits pass a
certain number of tests traditional with statisticians…
1951,D.H,Lehmer,Berkeley
Here is a page from
Lehmer's famous
dissertation on the
functions named after
the French
mathematician Edouard
Lucas (1842-1891),It
subsequently appeared
in Annals of
Mathematics and as a
monograph published
in Hamburg by Lutcke
& Wulff,both in 1930.
Lehmer's Algorithm
Multiplicative congruential algorithm,整数 a,c,m
种子:
0x
mcaxx kk m o d 1 ???
1 13 14 27 10 6 16 22 7 29 5 3 8
例如,a=13,c=0,m=31,x0=1,输出:
周期,m- 1。 可以通过除以 m来得到 [0,1]的一致分布的数
0.0323 0.4194 0.4516 0.8710 0.3226 0.1935 0.5161…
最小值,1/31,最大值,30/31
IBM's Algorithm
在 1960年 IBM主机系统的数学库包括随机数生成器:
RND(RNDU),312,0,6 5 5 3 9 ??? mca
用 32位的整数字长,mod m运算可以快速进行,同时由
于 a=2^16+3,乘 a也可以通过移位和加法进行。
k
k
kkk
x
x
xxx
]9)32(*6[
)92*62(
)32()32(
16
1632
216
1
16
2
???
???
???? ??
kkk xxx 9*6 12 ?? ??
从这里可以看出,由 RNDU生成的三个随机数之间有很
强的相关性
IBM's Algorithm
-1
-0.5
0
0.5
1
-1
-0.5
0
0.5
1
-1
-0.5
0
0.5
1
randgui randutx
Matlab's Algorithm
2 1 4 7 4 8 3 6 4 712,0,168077 315 ?????? mca
S.K.Park and K.W.Miller "Random number generators,Good
ones are hard to find",Comm ACM 31(1988),issue 10
randgui randtx
早期 Matlab中的 rand生成形似 k/m的所有的实数,最小是:
1/(2^31-1),最大是 (m-1)/m=1-1/(2^31-1),大概 2亿多个数。
Matlab's Algorithm
1995年,Matlab引入了一种完全不同的随机数生成器。
George Marsaglia,Florida State University,an author of the
classic analysis of random number generators,
"Random numbers fall mainly in the planes",(Proc,Nat.Acad.Sci,
61(1968)
这个算法是特别为浮点随机数设计的。
新的生成器有 35个字。其中 32个字存
浮点数 z,剩下 3个包括一个整数指标 i,
( 1~ 32),一个随机整数 j,和一个
"borrow"标志 b,
Matlab's Algorithm
,subtract with borrow”
bzzz iii ??? ?? 520
i,i+5,i+20都是 mod 32
如果 z_i是正的,b在下一步设为 0;如果是负的,那么
z_i+1变为正的,b在下一步设为 2^(-53) (ulp)
format hex; 1/2
1/2+eps
1/2+eps/2
ulp,unit in the last place for
floating point numbers slightly
less then 1
Marsaglia,1 4 3 02a l m o s t
将生成 [1/2,1]中全部的数,
[1/4,1/2]:一半
[1/8,1/4]:四分之一
Matlab's Algorithm
在状态向量中的 j的作用:
It is the result of a separate,independent,random number
generator based on bitwise logical operations,The
floating point fraction of each z_i is xor-ed with j to
produce the result returned by the generator.
We 're not sure whether or not they all actually
generated,but we don't know of any that can't be.
14922
Christopher Columbus generator
Cleve Morler著
陈文斌( wbchen@fudan.edu.cn)
复旦大学 2002
随机数
Pseudorandom Number
format long; rand
0.95012928514718
pseudorandom number:
A random sequence is a vague notion …,in which each term
is unpredictable to the uninitiated and whose digits pass a
certain number of tests traditional with statisticians…
1951,D.H,Lehmer,Berkeley
Here is a page from
Lehmer's famous
dissertation on the
functions named after
the French
mathematician Edouard
Lucas (1842-1891),It
subsequently appeared
in Annals of
Mathematics and as a
monograph published
in Hamburg by Lutcke
& Wulff,both in 1930.
Lehmer's Algorithm
Multiplicative congruential algorithm,整数 a,c,m
种子:
0x
mcaxx kk m o d 1 ???
1 13 14 27 10 6 16 22 7 29 5 3 8
例如,a=13,c=0,m=31,x0=1,输出:
周期,m- 1。 可以通过除以 m来得到 [0,1]的一致分布的数
0.0323 0.4194 0.4516 0.8710 0.3226 0.1935 0.5161…
最小值,1/31,最大值,30/31
IBM's Algorithm
在 1960年 IBM主机系统的数学库包括随机数生成器:
RND(RNDU),312,0,6 5 5 3 9 ??? mca
用 32位的整数字长,mod m运算可以快速进行,同时由
于 a=2^16+3,乘 a也可以通过移位和加法进行。
k
k
kkk
x
x
xxx
]9)32(*6[
)92*62(
)32()32(
16
1632
216
1
16
2
???
???
???? ??
kkk xxx 9*6 12 ?? ??
从这里可以看出,由 RNDU生成的三个随机数之间有很
强的相关性
IBM's Algorithm
-1
-0.5
0
0.5
1
-1
-0.5
0
0.5
1
-1
-0.5
0
0.5
1
randgui randutx
Matlab's Algorithm
2 1 4 7 4 8 3 6 4 712,0,168077 315 ?????? mca
S.K.Park and K.W.Miller "Random number generators,Good
ones are hard to find",Comm ACM 31(1988),issue 10
randgui randtx
早期 Matlab中的 rand生成形似 k/m的所有的实数,最小是:
1/(2^31-1),最大是 (m-1)/m=1-1/(2^31-1),大概 2亿多个数。
Matlab's Algorithm
1995年,Matlab引入了一种完全不同的随机数生成器。
George Marsaglia,Florida State University,an author of the
classic analysis of random number generators,
"Random numbers fall mainly in the planes",(Proc,Nat.Acad.Sci,
61(1968)
这个算法是特别为浮点随机数设计的。
新的生成器有 35个字。其中 32个字存
浮点数 z,剩下 3个包括一个整数指标 i,
( 1~ 32),一个随机整数 j,和一个
"borrow"标志 b,
Matlab's Algorithm
,subtract with borrow”
bzzz iii ??? ?? 520
i,i+5,i+20都是 mod 32
如果 z_i是正的,b在下一步设为 0;如果是负的,那么
z_i+1变为正的,b在下一步设为 2^(-53) (ulp)
format hex; 1/2
1/2+eps
1/2+eps/2
ulp,unit in the last place for
floating point numbers slightly
less then 1
Marsaglia,1 4 3 02a l m o s t
将生成 [1/2,1]中全部的数,
[1/4,1/2]:一半
[1/8,1/4]:四分之一
Matlab's Algorithm
在状态向量中的 j的作用:
It is the result of a separate,independent,random number
generator based on bitwise logical operations,The
floating point fraction of each z_i is xor-ed with j to
produce the result returned by the generator.
We 're not sure whether or not they all actually
generated,but we don't know of any that can't be.
14922
Christopher Columbus generator