Debug.Log affect the code?

I just learned something about unity.
I love it very much, but I had a problem when I used it.
I compiled a maze, (the picture 1)
but I am confused about the code in the program(the picture 3)
If I don’t delete, it will be the picture 1,
If I delete this code, the maze will be just like picture 2. It’s not what I want.
I tried to build and run, but the result of the operation is just like the picture 2

It is so queer. 

Software Development Environment:
mac 10.10.5 (14F1713)
unity  5.3.6f1 Personal

82570-picture3.png

The most likely way that using Debug.Log can affect code output is if you have some timing issues (normally involving multithreading) where the delay caused by logging to screen/file alters the order in which two functions return their output.

update I just noticed you’re using the System.Random class, but you’re not specifying an initial seed, so you’ll be using Environment.tickCount as the seed. Since Debug.Log takes more ticks, you’re getting a different seed.

We don’t know your maze generation code - are you using threads?