I assume that by "loops" you mean edges "x->x" from a node "x" to itself.
Yes, such edges may also exist (but apparently they will never appear in a shortest path), i.e., d(x,x) may be non-zero. You need not treat this case specially, just set (by application of a random number generator) for every node pair (x,y) the distance d(x,y) with the same probability "p" to a non-zero value.