private void generate() {
		rand = new Random();

		MazeNode initial = grid[rand.nextInt(x_Dim)][rand.nextInt(y_Dim)][rand
				.nextInt(z_Dim)];
		MazeNode current = initial;
		current.setVisited(true);
		int count = 1;
		int size = x_Dim * y_Dim * z_Dim;

		// checks if all nodes in maze have been visited; continues of not
		while (count < size) {
			// checks if all nodes adjacent to current have been visited;
			// continues if so
			if (!allVisited(current)) {
				MazeNode chosen = null;
				int dir = 0;
				// randomly chooses an unvisited adjacent node and moves to it
				while (chosen == null || chosen.isVisited()) {
					dir = rand.nextInt(6);
					chosen = current.getNeighbors()[dir];
				}
				// current node is pushed onto stack
				theStack.push(current);
				// wall is removed between current node and chosen node
				current.setWalls(false, dir);
				chosen.setWalls(false, oppDir(dir));
				// chosen node becomes current node and visited flag is set
				current = chosen;
				current.setVisited(true);
				// count is incremented
				count++;
				// checks if stack is empty; continues if so
			} else if (!theStack.isEmpty()) {
				// a node is popped from the stack and becomes current node
				current = theStack.pop();
				// if all adjacent nodes to current have been visited and the
				// stack is empty
				// a random unvisited node becomes the current node
			} else {
				MazeNode temp = current;
				while (temp.isVisited()) {
					temp = grid[rand.nextInt(x_Dim)][rand.nextInt(y_Dim)][rand
							.nextInt(z_Dim)];
				}
				current = temp;
				current.setVisited(true);
				count++;
			}
		}
		// start node is chosen
		startNode();
	}