# How to get random?

• Greetings!

I'm trying to achieve the following: Every time an object is spawned, certain qualities are set randomly. E.G.: the object is spawned and its rotation is random, so every time it spawns, it spawns with a different rotation. Ideas?

• Very simple indeed...

Here's how spawning works:

You spawn an object and it duplicates that object, along with all of its original behaviors. Keep in mind, you always do this in a different object, so as not to confuse yourself or duplicate the spawning behavior. Then, the new object executes its logic.

You can set a limitation on the number of objects in the scene, but there's no point in doing so. Basically, the objects will stop spawning after you reach a spawn count. And you have no control over what happens next.

Handle all the spawning logic yourself, in another behavior.

Keeping in mind that an object always spawns with its original behaviors, find the "random number" behavior in "logic" and set its range 0-360. Then output this value in a rotation-type behavior (found in the "transform" section).

Also, a tip: Don't be afraid to set the advanced dial for more behaviors. It's advantageous to have as many behaviors as possible, and you'll find that some are necessary. If I've used any advanced behaviors in this lecture, sorry.

But don't put the simpler behaviors in front of the advanced behaviors, because there's really no division.

Have fun working with Hyperpad! And tell me if you need more help with this or anything else! Depending on the task, I'll be more than happy to help! :)

• @This here's an image of what GameCRAZY said:

You tap "Change Manually" on the "Rotate to Angle" behaviour (under the transform section) and then drag the little Output box from the top right of the random number behaviour into the text field that appeared. You can set the random number 1 and 360 if you want it to be any integer rotation, 0.0 and 360.0 if you want decimals as well (although there is a bug where the maximum number will be higher than it should be in the non-beta version), and if you don't want it to be a full rotation, 0° is the default angle, so you can for example do 0 and 90 to rotate between 0° and 90°.

• Thanks to both of you. Another question, is it possible to do the same with a Set Color behavior? Can I have every time the object is spawned it set to a random color?

• @This it depends what exactly you want. If you want it to set randomly for a specific set of colours you could have a random number behaviour and then a bunch of ifs (if random=1, set to colour 1, etc.) if you want it to be a completely random colour, it's harder because hyperPad uses hexadecimal colour codes. You can check out my hex colour generator, but it's pretty complex and next update it'll be a lot easier to make hex codes because arrays will be added, so you can just use an array and get a colour using the index of how much red/blue/green the colour should have.

• @This

You really don't need the random-number/if behaviors Jack suggested for the colors. Just use the "execute sequence" behavior in "logic," and set it to "random." Then, attach whatever random color behaviors you want. I'd say make 5 different color options.

• @GameCRAZY oh yeah, I forgot about random execute sequence, that's a far better way.