How to set random X Y Location from script?
random.uniform(a, b) returns a random float between a and b

import bpy
from random import uniform
from mathutils import Vector

context = bpy.context
obj = context.object
minloc = 0
maxloc = 3

# set frame with scene.frame_set() 
# setting scene.frame_current wont always work.

scene.frame_set(frame)

for axis in "xy":
    setattr(obj.location, axis, uniform(minloc, maxloc))

obj.keyframe_insert('location', frane=frame, group="Location")


Scripts that loop thru frames and change frame using scene.frame_current = frame often appear to fail because only the first frame value is keyed as changing frame_current doesn't call a scene update, whereas set_frame does.