You might consider to use a tuple of directions, something like this:
```
directions = ((1,0), (0,1), (-1,0), (0,-1))
```
In your while loop, you can do:
```
direction = directions[np.random.randint(4)]
A += direction[0]
B += direction[1]
```
If you switch from tuple to numpy arrays (direction and your current position), you could also use numpy.add which might be faster. If this really improve performence you have to measure. To do this, you might use a seed for your random generator, to get reproducible code.