本帖最后由 布衣龙共 于 2021-1-12 15:04 编辑
[Fortran] 纯文本查看 复制代码 Module random_choice_FYS
implicit none
integer,parameter,private :: kq = 4
contains
Subroutine choice_FYS(x,y)
Integer :: x(:)
Integer,intent(INOUT) :: y(:)
integer :: m , p , j
real(kq) :: KK
m = size(x)
Do j = 1 , size(y)
call random_number(KK)
p=Int(KK*M)+1
if (p < m) x([p,m]) = x([m,p])
y(j) = x(m)
m = m - 1
End Do
End subroutine choice_FYS
End Module random_choice_FYS
Program Main
use random_choice_FYS
integer :: x(6) = [1,2,3,4,5,6]
integer :: y(3)
call random_seed()
call choice_FYS(x,y)
write(*,*) y
write(*,*) x
End Program Main
|