Can you please edit your post and format your code?
I’m sorry I’m not going more into what you have done so far but have you consider using PVector objects? They have very handdy methods for what you want to do. Here is an example:
PVector startPoint;
float l;
void setup() {
size(1280, 1024);
background(20);
stroke(200);
strokeWeight(1);
startPoint = new PVector(random(width), random(height)); // Initialize with a random point on the screen
l = random(50, 200); // Get a random length for the lines
frameRate(20);
}
void draw() {
PVector randomVec = PVector.random2D(); // Get a random vector
randomVec.mult(l); // Give that vector the length of your line
randomVec.add(startPoint); // Add it to the start point to figure out the end point
line(startPoint.x, startPoint.y, randomVec.x, randomVec.y); // Draw the line
startPoint = randomVec.copy(); // Keep he coordinate of that last point -> it will be the first point of the next line
}
Now, with the code you provided, you can do some cleaning. You have plenty of variables to keep track of just 4 points. So you want to get read of the zX, zY, fX, fY.
Then the basic idea to have an infinite loop is to set your end point as the start point for the new loop.
And to get the random direction, you simply need to get a random angle.
float a, b, c, d;
float dis = dist(0, 100, 0, 0);
void setup() {
size(1400, 800);
strokeWeight(1);
background(20);
stroke(200);
a = random(width);
b = random(height);
}
void draw() {
// Get the end point
float randomAngle = random(TWO_PI);
c = dis * cos(randomAngle) + a;
d = dis * sin(randomAngle) + b;
// Draw the line
line(a, b, c, d);
// Set the end point as the new start point for the next loop
a = c;
b = d;
}