要求是这样的:
1.Generate 20 or more random numbers using your LCG
function:U
1
,...,U
20
.
2.Pick one of these 20 numbers with equal probability,
1/20.This requires generating another random number
from a different stream.Assign the picked random
number from the U stream,say U
3
,to W,i.e.,W
1
=U
3
.
3.Replace the random number picked from the first
stream,say U
3
,with the next random number in the
sequence,i.e.,U
21
.
4.Repeat steps 2-3.This results in a shuffled sequence of
random numbers,W,of the initial sequence,U.
下面是我编的程序,我知道存在很大的问题,由于初学matlab实在是不知道怎么改进,
特别是当循环需要用上底标,而取矩阵值时也需要,而这怎么弄,还请大侠知道哈~~~
function [w]= Shuffling(n)
m=rand(1,n);
for i=1:n-20;
k=m(1:20);
k=subs(k,k(3),m(20+i));
k=k(randperm(20));
end
w=sum(k(3));