please format your code posting by pasting it into the
</> code button
of the editor header menu ( context name: Preformatted text )
it looks like
```
type or paste code here
```
also can use the ``` manually above and below your code.
thank you.
also when using p5.js
it might be better just to link to your online editor project / or MVCE
you draw line X Y only,
but use WEBGL renderer ( for 3D )
i show you there how to use constrain()
but there might be other way.
but the real question might be WHY
i think that is a tricky statistical question behind it, when you change randomly
the 4 parameters of a line, it can walk anywhere, can grow longer or shorter…
so limiting must not only be in X/Y canvas,
possibly also limit min max length!
and there i recommend to change all that code to PVector
possibly now want position the whole array ( of objects ) in 3D space
use like
translate(x,y,z);