How to resolve the algorithm Constrained random points on a circle step by step in the Frink programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Constrained random points on a circle step by step in the Frink programming language

Table of Contents

Problem Statement

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:
  2. Precalculate the set of all possible points (there are 404 of them) and select randomly from this set.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Constrained random points on a circle step by step in the Frink programming language

Source code in the frink programming language

g = new graphics

count = 0
do
{
   x = random[-15,15]
   y = random[-15,15]
   r = sqrt[x^2 + y^2]
   if 10 <= r and r <= 15
   {
       count = count + 1
       g.fillEllipseCenter[x,y,.3, .3]
   }
}  while count < 100

g.show[]

  

You may also check:How to resolve the algorithm Sequence of primes by trial division step by step in the Crystal programming language
You may also check:How to resolve the algorithm Generic swap step by step in the LOLCODE programming language
You may also check:How to resolve the algorithm Define a primitive data type step by step in the Delphi programming language
You may also check:How to resolve the algorithm GUI/Maximum window dimensions step by step in the BASIC programming language
You may also check:How to resolve the algorithm SHA-256 step by step in the NewLISP programming language