pxt-calliope/docs/blocks/math/random-boolean.md
2020-08-19 22:03:58 +02:00

591 B

random Boolean

Returns a pseudo-random boolean value that is either true or false.

Math.randomBoolean()

Returns

  • a pseudo-random boolean that is either true or false.

Example

Make your @boardname@ do a coin toss when it's dropped softly. Have the LEDs show 'heads' or 'tails' as the result of the toss.

input.onGesture(Gesture.FreeFall, () => {
    if (Math.randomBoolean()) {
        basic.showIcon(IconNames.Happy)
    } else {
        basic.showIcon(IconNames.Sword)
    }
})

See Also

random