# Select Random Objects with Name

I have many objects with the same name. I can search for these in the Collection window. I would like to select a random subset of these.

I can see that Blender 2.8 has a Select -> Select Random option, but this includes all visible objects.

• How about hiding all other objects temporarily? – Leander Jun 21 '19 at 7:00
• @Leander That would be an option. Is there a way to do this without 'un-hiding' any already hidden objects when making the original objects visible again? – rhughes Jun 21 '19 at 7:03

One option would be to use select random and then run a script that deselects anything that doesn't match the name that you specify.

import bpy

for o in bpy.context.visible_objects:
if 'gizmo' not in o.name.lower():
o.select_set(False)


Another way could be to make a list of objects matching the name criteria and then getting a random choice from that list and selecting them.

import bpy
from random import choices

bpy.ops.object.select_all(action='DESELECT')

objlist = [o for o in bpy.context.visible_objects
if 'gizmo' in o.name.lower()]

rand_list = choices(objlist, k=int(len(objlist) * .75))

for o in rand_list:
o.select_set(True)


In this example, I set the k parameter to be 75% of the object list. You could also specify an exact number of objects that you want selected.