lundi 19 avril 2021

How to Put Random Numbers into Loop in Fortran

I have the following code:

program outputdata   
implicit none

  real, dimension(100) :: x, y  
  real, dimension(100) :: p, q
  integer :: i  

  ! data  
  do i=1,100  
      x(i) = i * 0.1 
      y(i) = sin(x(i)) * (1-cos(x(i)/3.0))  
  end do  

  ! output data into a file 
  open(1, file = 'data1.dat', status = 'new')  
  do i=1,100  
      write(1,*) x(i), y(i)   
  end do  

  close(1) 

end program outputdata

I would like to write a very similar code but which uses a string of random numbers instead of 1-100 sequentially. I have found these codes for generating random number sequences:

real :: r(5)

call random_seed()
call random_number(r)

but I cannot seem to figure out how to combine the codes to input the random number vector into the loop.




Aucun commentaire:

Enregistrer un commentaire