1
我一直在努力解决问题,所以如果任何人可以提供任何建议或例子,它将非常感激。使用Fortran90。使用随机数字删除文件的随机行。 Fortran90
用途程序:
从文件中删除随机的线条,在我选择的数量。我能想到的最好的方法是使用随机数来对应一个行号。
它能做什么的那一刻:
每次生成新的随机数,并把它们输出到一个单独的文件。
问题:
(1)它不生成可对应于行数的整数。 (2)我不知道如何使用这些数字来删除文件中的行。
program random1
implicit none
integer :: i, seed, removed
real :: r
open (unit=10,file='random.dat')
removed=5
call init_random_seed()
do i=1,removed
call random_number(r)
write(10,*) r
end Do
end program random1
subroutine init_random_seed()
integer :: i,n,clock
integer, dimension(:),allocatable :: seed
call random_seed(size=n)
allocate(seed(n))
call system_clock(count=clock)
seed=clock+37*(/(i-1,i=1,n)/)
call random_seed(put=seed)
deallocate(seed)
end subroutine
谢谢!