Random
Random(10) gives a whole number from 0 to 9, and a bit of randomness makes a game feel alive.
How Random works
Random(n) gives a whole number from 0 up to one less than n. So Random(10) is 0, 1, 2 โฆ or 9, never 10. Each time the rule runs it picks again.
Random(2) | 0 or 1. A coin toss. |
|---|---|
Random(6) + 1 | 1 to 6. A dice. |
Random(600) | 0 to 599. Anywhere across a level 600 wide. |
Random(50) + 25 | 25 to 74. Add to shift the range. |
Random(4) * 100 | 0, 100, 200 or 300. Multiply for steps. |
Random places
Create things in a random spot. Use Random(FrameWidth) so it works whatever size the level is.
With Repeat the actionsโฆ you get several at once, each in a new place, because the formula runs again for each one.
Random speeds and directions
Directions go from 0 to 31, so Random(32) is any direction. For โleft or rightโ use the direction wheel in the settings instead and tick two directions: NutHouse picks one at random for you.
How to
- Open a settings dialog with a number box, for example โ Create objects โ Create an object.
- In X (across) type
Random(600). In Y (down) type 0. - Press Add and play. Each new coin drops from a different place.
Random chance
Sometimes you want a rule to run only now and then. Random chance in the โ Special column does this without a formula: โ1 chance in 10โ means about one try in every ten. It is the same as adding Random(10) = 0 with Compare two values.
Random objects
Random gives numbers. To choose one object out of many, use Pick one of them at random instead. See Pick one at random.