#遞迴(隨機)(地毯)
import numpy as np
import matplotlib.pyplot as plt
import random
plt.figure(figsize=(9,9),dpi=80)
(h,k)=(0,200)
(p,q)=(0,200)
def F(h,k,p,q):
if (k-h<=1 or q-p<=1):return
X=[h,k,k,h,h]
Y=[p,p,q,q,p]
plt.plot(X,Y,linewidth=2)
a=random.randint(h+1,k-1) #之間(含端點)的隨機整數
b=random.randint(p+1,q-1) #之間(含端點)的隨機整數
F(h+1,a,p+1,b)
F(a+1,k-1,p+1,b)
F(h+1,a,b+1,q-1)
F(a+1,k-1,b+1,q-1)
F(h,k,p,q)