How do you manipulate pose bones using python?
I'd avoid using ops to set the mode to Pose Mode.

Access the bones directly through the hierarchy as it is exposed through the api.

import bpy
import random

armature = bpy.context.scene.objects['Armature']

for pose_bone in armature.pose.bones:
    x = pose_bone.location[0] + random.uniform(-0.2, 0.2)
    y = pose_bone.location[1] + random.uniform(-0.2, 0.2)
    z = pose_bone.location[2] + random.uniform(-0.2, 0.2)
    pose_bone.location[0] = x
    pose_bone.location[1] = y
    pose_bone.location[2] = z