diff --git a/libs/microbit/helpers.ts b/libs/microbit/helpers.ts index 1e6bad4a..959c4ee5 100644 --- a/libs/microbit/helpers.ts +++ b/libs/microbit/helpers.ts @@ -4,3 +4,14 @@ namespace console { serial.writeString("\r\n"); } } + +namespace Math { + /** + * Generates a `true` or `false` value randomly, just like flipping a coin. + */ + //% blockId=logic_random block="pick random true or false" + //% help=math/random-boolean color=210 + export function randomBoolean(): boolean { + return Math.random(2) == 0; + } +} \ No newline at end of file