[LibGDX] Cave generation

Hi!
I have been reading this article: http://roguebasin.roguelikedevelopment.org/index.php?title=Basic_directional_dungeon_generation, but I cant understand what I am supposed to do: I dont even know when I am supposed to render any objects. Can anybody help me, and explain how that algorithm works, and how to implement it in my code? Thanks!

@edit: I have tried to implement the algorithm like this, but it crashes the Java Runtime! Here is the code:



public class MapGenerator {
	
	private int length, roughness, windyness, mapWidth;
	private int[] roll = { -2, -1, 1, 2 };
	private World world;
	
	public MapGenerator(int length, int roughness, int windyness, int mapWidth, World world) {
		this.length = length;
		this.roughness = roughness;
		this.windyness = windyness;
		this.mapWidth = mapWidth;
		this.world = world;
	}
	
	public void generate(int startingX, int startingY, int startingWidth) {
		int x, y, width;
		x = startingX;
		y = startingY;
		width = startingWidth;
		Random r = new Random();
		
		BodyDef bodyDef = new BodyDef();
		FixtureDef fixtureDef = new FixtureDef();
		
		for (int a = 0; a <= length; a++) {
			y++;
			if (r.nextInt(100) <= roughness) {
				int ro = r.nextInt(4);
				width += roll[ro];
				
				if (width > 3) 
					width = 3;	
				
				if (width > mapWidth)
					width = mapWidth;
			}
			
			if (r.nextInt(100) <= windyness) {
				int ro = r.nextInt(4);
				x += roll[ro];
				
				if (x < 0)
					x = 0;
				
				if (x > mapWidth - 3)
					x = mapWidth - 3;
			}
			
			bodyDef.type = BodyType.StaticBody;
			bodyDef.position.set(x, y);
			
			ChainShape shape = new ChainShape();
			shape.createChain(new Vector2[] {
				new Vector2(x, y),
				new Vector2(x + width, y),
				new Vector2(x + width, y),
				new Vector2(x, y)
			});
			
			fixtureDef.shape = shape;
			fixtureDef.density = 3;
			fixtureDef.restitution = 0.2f;
			fixtureDef.friction = 0.2f;
			
			world.createBody(bodyDef).createFixture(fixtureDef);
		}
	}
	
}