How to make an object move in a random way or change direction

Hello,

   I am trying make a 3d object move randomly in 3d environment similar to this https://www.youtube.com/watch?v=bEo8YRHysp8. 

I tried with the following code but ended up in jerks between the movements and the movements were not clear. Please help me. Thanks in advance

import bpy
import math
import mathutils
import random




bpy.app.handlers.frame_change_pre.clear()
ob = bpy.data.objects.get("Cube")
ob.location = mathutils.Vector((0.0, 0.0, 0.0))






# every frame change, this function is called.
def my_handler(scene):
    if random.randint(1, 10) > 9:
        x = random.uniform(-0.7, 0.7)
        #print (x)
        vec = mathutils.Vector((0.0, x, 0.0))
        ob.location = ob.location + vec
	else:
		vec = mathutils.Vector((0.0, 0.0, 0.0))
        ob.location = ob.location + vec




bpy.app.handlers.frame_change_pre.append(my_handler)