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) + 11 to 6. A dice.
Random(600)0 to 599. Anywhere across a level 600 wide.
Random(50) + 2525 to 74. Add to shift the range.
Random(4) * 1000, 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.

WhenEvery 2000 ms
DoCreate Coin at (Random(FrameWidth), 0)

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

WhenStart of level
DoSet speed of Ball to Random(30) + 20Set direction of Ball to Random(32)

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

  1. Open a settings dialog with a number box, for example โœš Create objects โ†’ Create an object.
  2. In X (across) type Random(600). In Y (down) type 0.
  3. 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.

Still stuck?

Try the Chocobreak tutorial, open a sample game and read its rules, or look at the questions people ask.