Random Fortran中的随机数组/矩阵初始化
有没有一种方法可以在不使用显式do循环的情况下初始化随机数组 现在我的随机矩阵初始化看起来像Random Fortran中的随机数组/矩阵初始化,random,matrix,fortran,fortran95,Random,Matrix,Fortran,Fortran95,有没有一种方法可以在不使用显式do循环的情况下初始化随机数组 现在我的随机矩阵初始化看起来像 program Main implicit none save integer :: seed, i, j real :: x character(100) :: option real, dimension(10,10) :: matrix if (iargc() > 0) then CALL GETARG(1,opti
program Main
implicit none
save
integer :: seed, i, j
real :: x
character(100) :: option
real, dimension(10,10) :: matrix
if (iargc() > 0) then
CALL GETARG(1,option)
read(option,*) seed
else
seed = 1
end if
call RANDOM_SEED(seed)
do i=1,10
do j=1,10
call RANDOM_NUMBER(x)
matrix(i,j) = x
end do
end do
end program
但如果可能的话,我希望它更接近隐含的do循环数组初始化:
program Main
implicit none
save
integer :: seed
character(100) :: option
real, dimension(10,10) :: matrix
if (iargc() > 0) then
CALL GETARG(1,option)
read(option,*) seed
else
seed = 5
end if
call RANDOM_SEED(seed)
matrix = reshape((/ ((call RANDOM_NUMBER()), i=1,100) /), shape(matrix))
end program
Fortran 95有没有可能实现类似的功能?为什么没有
调用随机数(矩阵)
?+1,或者,正如人们可能会说的那样,为什么不阅读Fortran手册呢?因为这样,未来的人们可以通过他们喜爱的搜索引擎更容易地找到答案。