Consider:
I'm having trouble with making each of these circles to have a random color and the problem is that the color is random, but that color applies to all of them.
import bpy
import random as r
import math as m
n=25
for i in range(1,n+1):
material_i= bpy.data.materials.new(f'm{i}')
material_i.diffuse_color=(r.uniform(0,1),r.uniform(0,1),r.uniform(0,1),1)
bpy.context.object.data.materials.append(material_i)
angle = ((i-1)*4*(m.pi))/n
bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 0, 0), "orient_type":'GLOBAL', "orient_matrix":((0, 0, 0), (0, 0, 0), (0, 0, 0)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":False, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False})
bpy.context.object.rotation_euler[2] = angle