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
謝謝!