How to resolve the algorithm Constrained random points on a circle step by step in the Locomotive 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 Locomotive 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.

  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 Locomotive Basic programming language

Source code in the locomotive programming language

10 MODE 1:RANDOMIZE TIME
20 FOR J=1 TO 100
30 X=INT(RND*30-15)
40 Y=INT(RND*30-15)
50 D=X*X+Y*Y
60 IF D<100 OR D>225 THEN GOTO 40
70 PLOT 320+10*X,200+10*Y:LOCATE 1,1:PRINT J
80 NEXT
90 CALL &BB06 ' wait for key press

  

You may also check:How to resolve the algorithm Binary search step by step in the J programming language
You may also check:How to resolve the algorithm A+B step by step in the OCaml programming language
You may also check:How to resolve the algorithm Loops/Continue step by step in the Scheme programming language
You may also check:How to resolve the algorithm Character codes step by step in the TI-83 BASIC programming language
You may also check:How to resolve the algorithm Ackermann function step by step in the XPL0 programming language