The following VBA example creates 100 random circles in the active document, with optimization enabled for increased performance.
Sub Optimize()
Dim i As Long
Dim x As Double, y As Double, r As Double
Dim n As Long
Dim num As Long
Dim MaxX As Double, MaxY As Double, MaxR As Double
MaxX = ActivePage.SizeWidth
MaxY = ActivePage.SizeHeight
MaxR = 1
num = ActivePalette.ColorCount
Optimization = True
For i = 1 To 100
x = Rnd() * MaxX
y = Rnd() * MaxY
r = Rnd() * MaxR
n = CLng(Fix(Rnd() * num)) + 1
Set s = ActiveLayer.CreateEllipse2(x, y, r)
s.Fill.ApplyUniformFill ActivePalette.Color(n)
Next i
Optimization = False
ActiveWindow.Refresh
End Sub