How to resolve the algorithm Constrained random points on a circle step by step in the Liberty BASIC 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 Liberty BASIC 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.
- Generate random pairs of integers and filter out those that don't satisfy this condition:
- 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 Liberty BASIC programming language
Source code in the liberty programming language
' RC Constrained Random Points on a Circle
nomainwin
WindowWidth =400
WindowHeight =430
open "Constrained Random Points on a Circle" for graphics_nsb as #w
#w "trapclose [quit]"
#w "down ; size 7 ; color red ; fill black"
for i =1 to 1000
do
x =int( 30 *rnd( 1)) -15
y =int( 30 *rnd( 1)) -15
loop until IsInRange( x, y) =1
#w "set "; 200 +10 *x; " "; 200 - 10 *y
next
wait
function IsInRange( x, y)
z =sqr( x*x +y*y)
if 10 <=z and z <=15 then IsInRange =1 else IsInRange =0
end function
[quit]
close #w
end
You may also check:How to resolve the algorithm Arena storage pool step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Memory allocation step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Square-free integers step by step in the 11l programming language
You may also check:How to resolve the algorithm Function definition step by step in the Perl programming language
You may also check:How to resolve the algorithm Subleq step by step in the Forth programming language