How to set random X Y Location from script? I want to set random X Y location between a float range, lets say 1 to 3, and I want to set a keyframe after that. I came across this script but I couldn't figure how to set location from random:

import bpy
import math

ctx = bpy.context
ops = bpy.ops

ctx.scene.frame_start = 0
ctx.scene.frame_end = 400

ctx.scene.frame_current = 0


for i in range(400)
    ctx.scene.frame_current = i
    //how to set random locatio here?
    ops.anim.keyframe_insert_menu(type='Location')


Any tips are welcome.
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.