public static char[][] generate(int size) {
        if (size < 2) size=2;
        
        Random rand = new Random();
        
        char[][] map = new char[size][size];
        
        //initialize the map
        for (int x=0; x<size; x++){
            for (int y=0; y<size; y++){
                map[x][y] = ' ';
            }
        }
        
        //create 1-3 obstacles per 20 tiles
        int obstacleDensity = rand.nextInt(2)+1;
        int area = size*size;
        int numObstacles = (int) Math.round(area*0.05*obstacleDensity);
        
        for (int i=0; i<numObstacles; i++){
            //obstacles are 1-5 tiles long. However the max length for an obstacle is size-1;
            int obstacleSize = rand.nextInt(Math.min(size-1, 4))+1;
            boolean horizontal = rand.nextBoolean();

            //random start position
            int obstacleX = rand.nextInt(size);
            int obstacleY = rand.nextInt(size);
            
            //put obstacle on the map
            for (int j=0; j<obstacleSize; j++){
                if (obstacleX >= size || obstacleY >= size) break;
                map[obstacleX][obstacleY] = 'X';
                if (horizontal) obstacleX++;
                else obstacleY++;
            }
        }
        
        //set start and finish points
        map[0][0] = 's';
        map[size-1][size-1] = 'f';
        
        return map;
    }