In this code I can move a bone while in PoseMode but unfortunately I can’t rotate it, though it seems like the rotation changes it might need to get updated somehow.
import bpy
import random
import math
is_pose_mode = True if bpy.context.mode == 'POSE' else False
is_armature = True if bpy.context.object.type == 'ARMATURE' else False
if is_pose_mode and is_armature:
armature = bpy.data.objects[bpy.context.active_object.name]
bone = armature.pose.bones[bpy.context.active_pose_bone.name]
location = bone.location
rotation = bone.rotation_euler
location.x = (random.random() * 4) - 2
rotation.x = random.random() * math.pi
print("Location: " + str(location))
print("Rotation: " + str(rotation))