program randomEG
implicit none
integer :: k, i,j, temp, n=10000
real :: r
integer, dimension(8) :: values
! Declare an assumed shape, dynamic array
integer, dimension(:), allocatable :: seed
integer, dimension(:), allocatable :: results
! gfortran subroutine to return date and time information
! from the real time system clock. Works down to milliseconds
! and stores the eight return values in array values.
call date_and_time(VALUES=values)
! restart the state of the pseudorandom number generator
! k = minimum size of seed (12 on my system)
call random_seed(size=k)
! allocate memory to seed
allocate(seed(k))
allocate(results(n))
! assign information in values to seed
seed(:) = values(:)
! seed the random number generator
call random_seed(put=seed)
do i=1,n
results(i) = irand()
end do
do i=1,n
do j=i+1,n
if (results(i) > results(j)) then
temp = results(i)
results(i) = results(j)
results(j) = temp
endif
enddo
enddo
do i=1,n
print *, results(i)
end do
end program randomEG
温馨提示:答案为网友推荐,仅供参考