I got better results with Python with a nested comprehension with no random numbers:
A=[[j for i in range(n)] for j in range(n)]
B=[[i for i in range(n)] for j in range(n)]
Anyway also with your code I got much more performance than you listed, could be the pyc cache.