# To create a random rotation for each instance following precise angles

Hello,

please excuse me for my english

I try to make random rotations at each instance while following specific data (0,90,180,270) so that we can have diversity with my different faces of my cube.

I’m a beginner, and I’m totally stuck.

Hello,
You can use script chop to obtain 3 channels with randomly distributed 0, 90, 180, 270 values as:

``````# me is this DAT.
#
# scriptOp is the OP which is cooking.
import random
# press 'Setup Parameters' in the OP to call this function to re-create the parameters.
def setupParameters(scriptOp):
scriptOp.appendParInt('Samples', page='Custom')

scriptOp.par.Samples.normMin = 1
scriptOp.par.Samples.normMax = 100

return

# called whenever custom pulse parameter is pushed
def onPulse(par):
return

def cook(scriptOp):
scriptOp.clear()

# get value from custom parameter
scriptOp.numSamples = scriptOp.par.Samples

for name in ['rx', 'ry', 'rz']:
newchan = scriptOp.appendChan(name)

chan1 = scriptOp['rx']
chan2 = scriptOp['ry']
chan3 = scriptOp['rz']
for i in range(scriptOp.numSamples):
chan1[i] = random.randint(0,3)*90
chan2[i] = random.randint(0,3)*90
chan3[i] = random.randint(0,3)*90
return
``````

randomFaces1.toe (5.6 KB)

Hope that helps,
Jacques

Hey @Cam.Vye,

another option would be to use a Pattern CHOP. The “type” parameter can be set to `Random Non-Repeating Integers`. Now also set the “Range” parameter to `0` - `3` which will result in random values between 0 and 3 over the full length of the channel.

The nice thing about the Pattern CHOP is that you can feed it an input and it automatically adjusts it’s length to the input length with the benefit that changing the number of cubes will automatically be reflected in the Pattern CHOP as well. Specify the `rx ry rz` channel names in the “Channel Names” parameter and you get 3 rotation channels (optionally you can also say `r[xyz]`). Now on the Channel parameter page select `Append` from the “Combine Channels” parameter and the new rotation channels are appended to the translate channels.

This you can multiply with a Math CHOP by `90` to get your 0-270 degree value range. Make sure to set the “scope” parameter on the common page of the Math CHOP to `rx ry rz` so that the CHOP only affects the rotation channels and leaves the translate channels untouched.

Cheers
Markus

I just tried both solutions and both helped and learned a lot. The second is much simpler for someone like me who isn’t comfortable with code.

Thank you @jacqueshoepffner and @snaut for your help !

1 Like