BGE: realtime random shape generator (python)
I have modified the code as follows :


added a dictionary that stores the vertex position and the generated offset by random.uniform()
for each vertex check if there is already an offset for this position , if so we add this offset to the old position
if there is no offset calculated for this position we generate a new one and store it in the dictionary, we also add it to the old position


this method gives the vertices that has the same position  the same offseet



from bge import logic
import random
from mathutils import Vector

cont = logic.getCurrentController()
object = cont.owner

for mesh in object.meshes:
   print(mesh)
   verts_shift = dict()
   for m_index in range(len(mesh.materials)):
      print(m_index)
      for v_index in range(mesh.getVertexArrayLength(m_index)):
         print(v_index)
         vertex = mesh.getVertex(m_index, v_index)
         xyz_old= vertex.getXYZ().freeze()
         xyz_shift = verts_shift.get(xyz_old, None) 
         if xyz_shift :
             vertex.setXYZ(xyz_old+xyz_shift)
         else :
             xyz_shift = Vector(( random.uniform(-0.5,0.5), random.uniform(-0.5,0.5), random.uniform(-0.5,0.5) ))
             verts_shift[xyz_old] = xyz_shift
             vertex.setXYZ(xyz_old+xyz_shift)           

         print(xyz_old, xyz_shift)