Randomization - Create Objects

Add this script to a "Batch Script" editor (F10) and execute it with Script > Run.

The script creates a given number of random objects, and creates random positions within in a volume of 10 m x 10 m x 10 m, scales, and colours:

# Load Python's random number generator
import random

# Define how many objects and the max position where to place them 
numOfObjects = 10
maxPosition  = 5.0

# Create a loop for the number of objects
for i in range(0,numOfObjects):
 
	# Define a random number for the object type and scale
	randomObject = random.randint(1,4)
	randomScale  = random.uniform(0.5, 1.5)
 
	# Add a new object based on the random number
	if (randomObject == 1): newObject = scene.addSphere(3)
	if (randomObject == 2): newObject = scene.addCapsule()
	if (randomObject == 3): newObject = scene.addCube()
	if (randomObject == 4): newObject = scene.addCone(10)

	# Define a random position within ±maxPosition in XYZ direction
	posX = random.uniform(-maxPosition, maxPosition)
	posY = random.uniform(-maxPosition, maxPosition)
	posZ = random.uniform(-maxPosition, maxPosition)
 
	# Define a random RGB colour
	colR = random.randint(0,255)
	colG = random.randint(0,255)
	colB = random.randint(0,255)
 
	# Apply all random values to the new object
	newObject.setParameter("Position", Vector.new(posX, posY, posZ))
	newObject.setParameter("Scale", Vector.new(1.0, 1.0, 1.0).scale(randomScale))
	newObject.setParameter("Color", Vector.new(colR, colG, colB))