Task

Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 




10
≤



x

2


+

y

2




≤
15


{\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15}

. 
Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of points plotted may be less than 100, given that some pairs may be generated more than once.

There are several possible approaches to accomplish this. Here are two possible algorithms.

1) Generate random pairs of integers and filter out those that don't satisfy this condition:





10
≤



x

2


+

y

2




≤
15


{\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15}

.
2) Precalculate the set of all possible points (there are 404 of them) and select randomly from this set.




program Constrained_Points
  implicit none
 
  integer, parameter :: samples = 100
  integer :: i, j, n, randpoint
  real :: r
 
  type points
    integer :: x, y
  end type
 
  type(points) :: set(500), temp
 
! Create set of valid points
  n = 0
  do i = -15, 15
    do j = -15, 15
      if(sqrt(real(i*i + j*j)) >= 10.0 .and. sqrt(real(i*i + j*j)) <= 15.0) then
        n = n + 1
        set(n)%x = i
        set(n)%y = j
      end if
    end do
  end do
 
! create 100 random points
! Choose a random number between 1 and n inclusive and swap point at this index with point at index 1
! Choose a random number between 2 and n inclusive and swap point at this index with point at index 2
! Continue in this fashion until 100 points have been selected
  call random_seed
  do i = 1, samples
    call random_number(r)
    randpoint = r * (n + 1 - i) + i
    temp = set(i)
    set(i) = set(randpoint)
    set(randpoint) = temp
  end do
 
! In order to facilitate printing sort random points into ascending order
! sort x in ascending order
  do i = 2, samples
     j = i - 1
     temp = set(i)
        do while (j>=1 .and. set(j)%x > temp%x)
           set(j+1) = set(j)
           j = j - 1
        end do
     set(j+1) = temp
  end do
 
! sort y in ascending order for same x
  do i = 2, samples
     j = i - 1
     temp = set(i)
        do while (j>=1 .and. set(j)%x == temp%x .and. set(j)%y > temp%y)
           set(j+1) = set(j)
           j = j - 1
        end do
     set(j+1) = temp
  end do
 
! print circle
  write(*,"(a,a)", advance="no") repeat(" ", set(1)%y+15), "*"
  do i = 2, samples
    if(set(i)%x == set(i-1)%x) then
      write(*,"(a,a)", advance="no") repeat(" ", set(i)%y - set(i-1)%y-1), "*"
    else
      n = set(i)%x - set(i-1)%x
      do j = 1, n
        write(*,*)
      end do
      write(*,"(a,a)", advance="no") repeat(" ", set(i)%y+15), "*"
    end if
  end do
 
end program