From 6f148c14e0bae63bf81256a14ac80c855024cefc Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Fri, 1 Jun 2018 11:42:38 -0700 Subject: [PATCH] Fix randomInt --- docs/blocks/logic/boolean.md | 2 +- docs/courses/csintro/arrays/activity.md | 8 ++++---- docs/courses/csintro/arrays/unplugged.md | 6 +++--- docs/courses/csintro/booleans/project.md | 6 +++--- docs/courses/csintro/conditionals/activity.md | 2 +- docs/courses/csintro/conditionals/project.md | 8 ++++---- docs/courses/csintro/coordinates/activity.md | 4 ++-- docs/courses/csintro/coordinates/project.md | 8 ++++---- docs/device/crocodile-clips.md | 2 +- docs/examples/pi-montecarlo.md | 4 ++-- docs/examples/rando.md | 2 +- docs/examples/stop-watch.md | 2 +- docs/lessons/bop-it/activity.md | 2 +- docs/lessons/bop-it/quiz-answers.md | 14 +++++++------- docs/lessons/catch-the-egg-game.md | 2 +- docs/lessons/catch-the-egg-game/activity.md | 8 ++++---- docs/lessons/catch-the-egg-game/quiz-answers.md | 2 +- docs/lessons/catch-the-egg-game/tutorial.md | 2 +- docs/lessons/dice-roll.md | 2 +- docs/lessons/dice-roll/activity.md | 10 +++++----- docs/lessons/dice-roll/challenges.md | 6 +++--- docs/lessons/dice-roll/quiz-answers.md | 10 +++++----- docs/lessons/guess-the-number.md | 2 +- docs/lessons/guess-the-number/activity.md | 4 ++-- docs/lessons/guess-the-number/challenges.md | 4 ++-- docs/lessons/guess-the-number/quiz-answers.md | 4 ++-- docs/lessons/guess-the-number/quiz.md | 2 +- docs/lessons/guess-the-number/tutorial.md | 2 +- docs/lessons/headbands/activity.md | 6 +++--- docs/lessons/headbands/quiz-answers.md | 2 +- docs/lessons/hero/activity.md | 8 ++++---- docs/lessons/love-meter.md | 2 +- docs/lessons/love-meter/activity.md | 4 ++-- docs/lessons/love-meter/challenges.md | 8 ++++---- docs/lessons/love-meter/quiz-answers.md | 2 +- docs/lessons/love-meter/quiz.md | 2 +- docs/lessons/magic-8.md | 2 +- docs/lessons/magic-8/activity.md | 10 +++++----- docs/lessons/magic-8/challenges.md | 8 ++++---- docs/lessons/magic-8/quiz-answers.md | 8 ++++---- docs/lessons/magic-8/tutorial.md | 2 +- docs/lessons/spinner.md | 2 +- docs/lessons/spinner/activity.md | 6 +++--- docs/lessons/spinner/challenges.md | 6 +++--- docs/lessons/spinner/quiz-answers.md | 6 +++--- docs/lessons/truth-or-dare.md | 2 +- docs/lessons/truth-or-dare/activity.md | 6 +++--- docs/lessons/truth-or-dare/challenges.md | 6 +++--- docs/lessons/truth-or-dare/quiz-answers.md | 4 ++-- docs/lessons/truth-or-dare/tutorial.md | 4 ++-- docs/projects/infection.md | 4 ++-- docs/projects/love-meter.md | 4 ++-- docs/projects/reaction-time/code.md | 14 +++++++------- docs/projects/rock-paper-scissors/code.md | 12 ++++++------ docs/projects/rps-teams.md | 10 +++++----- docs/projects/salute.md | 4 ++-- docs/reference/input/on-button-pressed.md | 2 +- docs/reference/input/on-gesture.md | 2 +- docs/tutorials/getting-started.md | 2 +- docs/tutorials/hour-of-code/rock-paper-scissors.md | 12 ++++++------ libs/core/helpers.ts | 8 +------- 61 files changed, 152 insertions(+), 158 deletions(-) diff --git a/docs/blocks/logic/boolean.md b/docs/blocks/logic/boolean.md index b50d15d7..f9aa127c 100644 --- a/docs/blocks/logic/boolean.md +++ b/docs/blocks/logic/boolean.md @@ -18,7 +18,7 @@ When you compare two Numbers, you get a Boolean value, such as the comparison `x ```blocks input.onButtonPressed(Button.A, () => { - let x = Math.randomInt(5) + let x = Math.randomRange(0, 5) if(x < 5) { basic.showString("low"); } else { diff --git a/docs/courses/csintro/arrays/activity.md b/docs/courses/csintro/arrays/activity.md index 1f3ae2a5..cc3b53b0 100644 --- a/docs/courses/csintro/arrays/activity.md +++ b/docs/courses/csintro/arrays/activity.md @@ -200,14 +200,14 @@ Review the use of the random block in the Math category. * Create a block that will plot a single dot at a random location on the screen by choosing a random number from 0 to 4 for the x axis and a random number from 0 to 4 for the y axis. ```blocks -led.plot(Math.randomInt(5), Math.randomInt(5)) +led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5)) ``` Next, let’s create a loop that will repeat the above code five times, for a constellation with five stars. ```blocks for (let index = 0; index <= 4; index++) { - led.plot(Math.randomInt(5), Math.randomInt(5)) + led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5)) } ``` @@ -238,7 +238,7 @@ To fix this, we need to do a little math by subtracting 1 from whatever the valu let list = [5, 2, 1, 3, 4] for (let index = 0; index < list[0] - 1; index++) { - led.plot(Math.randomInt(5), Math.randomInt(5)) + led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5)) } ``` @@ -253,7 +253,7 @@ let list: number[] = [] input.onButtonPressed(Button.A, () => { for (let i = 0; i <= list.length - 1; i++) { for (let j = 0; j <= list[i] - 1; j++) { - led.plot(Math.randomInt(5), Math.randomInt(5)) + led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5)) } basic.pause(1000) basic.clearScreen() diff --git a/docs/courses/csintro/arrays/unplugged.md b/docs/courses/csintro/arrays/unplugged.md index 4330a73a..c66698b1 100644 --- a/docs/courses/csintro/arrays/unplugged.md +++ b/docs/courses/csintro/arrays/unplugged.md @@ -62,7 +62,7 @@ let column = 0 let index = 0 input.onButtonPressed(Button.AB, () => { for (let index = 0; index <= 4; index++) { - list[index] = Math.randomInt(5) + 1 + list[index] = Math.randomRange(0, 5) + 1 } }) input.onButtonPressed(Button.B, () => { @@ -142,7 +142,7 @@ input.onButtonPressed(Button.B, () => { }) input.onButtonPressed(Button.AB, () => { for (let index = 0; index <= 4; index++) { - list[index] = Math.randomInt(5) + 1 + list[index] = Math.randomRange(0, 5) + 1 } }) input.onButtonPressed(Button.A, () => { @@ -223,7 +223,7 @@ input.onButtonPressed(Button.A, () => { }) input.onButtonPressed(Button.AB, () => { for (let index = 0; index <= 4; index++) { - list[index] = Math.randomInt(5) + 1 + list[index] = Math.randomRange(0, 5) + 1 } }) input.onButtonPressed(Button.B, () => { diff --git a/docs/courses/csintro/booleans/project.md b/docs/courses/csintro/booleans/project.md index 23fb52b0..9eb2f779 100644 --- a/docs/courses/csintro/booleans/project.md +++ b/docs/courses/csintro/booleans/project.md @@ -196,7 +196,7 @@ let player1Turn = false let spin = 0 let delay = 0 input.onGesture(Gesture.Shake, () => { - if (player1Turn == true && Math.randomInt(4) < 3) { + if (player1Turn == true && Math.randomRange(0, 4) < 3) { basic.clearScreen() delay = 0 while (delay < 500) { @@ -241,7 +241,7 @@ input.onGesture(Gesture.Shake, () => { } else if (player1Turn) { basic.showString("Crash!") player1Turn = false - } else if (Math.randomInt(4) < 3) { + } else if (Math.randomRange(0, 4) < 3) { basic.clearScreen() delay = 0 while (delay < 500) { @@ -305,7 +305,7 @@ Here is a portion of the board game's code. A boolean variable is used to determ ```blocks let player1Turn = false; input.onGesture(Gesture.Shake, () => { - if (player1Turn == true && Math.randomInt(4) < 3) { + if (player1Turn == true && Math.randomRange(0, 4) < 3) { } }) diff --git a/docs/courses/csintro/conditionals/activity.md b/docs/courses/csintro/conditionals/activity.md index e5eac14e..ade1caa8 100644 --- a/docs/courses/csintro/conditionals/activity.md +++ b/docs/courses/csintro/conditionals/activity.md @@ -34,7 +34,7 @@ Here's an example mod: ```blocks let hand = 0 input.onGesture(Gesture.Shake, () => { - hand = Math.randomInt(3) + hand = Math.randomRange(0, 3) if (hand == 0) { basic.showLeds(` # # # # # diff --git a/docs/courses/csintro/conditionals/project.md b/docs/courses/csintro/conditionals/project.md index ee24641d..ea05e1f6 100644 --- a/docs/courses/csintro/conditionals/project.md +++ b/docs/courses/csintro/conditionals/project.md @@ -59,7 +59,7 @@ input.onButtonPressed(Button.B, () => { basic.showNumber(p2) }) input.onGesture(Gesture.Shake, () => { - if (Math.randomInt(p1 + p2 - 1 + 1) + 1 <= p1) { + if (Math.randomRange(0, p1 + p2 - 1 + 1) + 1 <= p1) { basic.showString("A") } else { basic.showString("B") @@ -118,10 +118,10 @@ let previous_roll = 0 input.onButtonPressed(Button.AB, () => { previous_roll = 0 if (4 <= previous_roll) { - yes_or_no = Math.randomInt(8) + yes_or_no = Math.randomRange(0, 8) } if (4 > previous_roll) { - yes_or_no = Math.randomInt(5) + yes_or_no = Math.randomRange(0, 5) } if (2 < yes_or_no) { basic.showString("YES") @@ -132,7 +132,7 @@ input.onButtonPressed(Button.AB, () => { } }) input.onGesture(Gesture.Shake, () => { - current_roll = Math.randomInt(6) + current_roll = Math.randomRange(0, 6) basic.showNumber(current_roll + 1) basic.pause(5000) basic.clearScreen() diff --git a/docs/courses/csintro/coordinates/activity.md b/docs/courses/csintro/coordinates/activity.md index 2f570ec6..3d474804 100644 --- a/docs/courses/csintro/coordinates/activity.md +++ b/docs/courses/csintro/coordinates/activity.md @@ -96,7 +96,7 @@ Steps: input.onButtonPressed(Button.A, () => {    basic.clearScreen()    for (let index = 0; index <= 4; index++) { -       led.plot(index, Math.randomInt(5)) +       led.plot(index, Math.randomRange(0, 5))    } }) ``` @@ -117,7 +117,7 @@ Here is the complete program: input.onButtonPressed(Button.A, () => {    basic.clearScreen()    for (let index = 0; index <= 4; index++) { -       led.plot(index, Math.randomInt(5)) +       led.plot(index, Math.randomRange(0, 5))    } }) input.onButtonPressed(Button.B, () => { diff --git a/docs/courses/csintro/coordinates/project.md b/docs/courses/csintro/coordinates/project.md index 9c6309cb..eafdbea6 100644 --- a/docs/courses/csintro/coordinates/project.md +++ b/docs/courses/csintro/coordinates/project.md @@ -150,7 +150,7 @@ basic.forever(() => {    } else {        game.addScore(1)        ball.set(LedSpriteProperty.Y, 0) -       ball.set(LedSpriteProperty.X, Math.randomInt(5)) +       ball.set(LedSpriteProperty.X, Math.randomRange(0, 5))    } }) input.onButtonPressed(Button.A, () => { @@ -163,7 +163,7 @@ input.onButtonPressed(Button.B, () => {        dodger.change(LedSpriteProperty.X, 1)    } }) -ball = game.createSprite(Math.randomInt(5), 0) +ball = game.createSprite(Math.randomRange(0, 5), 0) dodger = game.createSprite(2, 4) game.setScore(0) ``` @@ -182,7 +182,7 @@ basic.forever(() => {    } else {        game.addScore(1)        ball.set(LedSpriteProperty.Y, 0) -       ball.set(LedSpriteProperty.X, Math.randomInt(5)) +       ball.set(LedSpriteProperty.X, Math.randomRange(0, 5))    } }) input.onButtonPressed(Button.A, () => { @@ -195,7 +195,7 @@ input.onButtonPressed(Button.B, () => {        dodger.change(LedSpriteProperty.X, 1)    } }) -ball = game.createSprite(Math.randomInt(5), 0) +ball = game.createSprite(Math.randomRange(0, 5), 0) dodger = game.createSprite(2, 4) game.setScore(0) ``` diff --git a/docs/device/crocodile-clips.md b/docs/device/crocodile-clips.md index 08ad462b..106a8599 100644 --- a/docs/device/crocodile-clips.md +++ b/docs/device/crocodile-clips.md @@ -39,7 +39,7 @@ the @boardname@ will return a random Number between 0 and the parameter limit. ```blocks input.onPinPressed(TouchPin.P0, () => { - basic.showNumber(Math.randomInt(10)) + basic.showNumber(Math.randomRange(0, 10)) }) ``` diff --git a/docs/examples/pi-montecarlo.md b/docs/examples/pi-montecarlo.md index e2ed2672..8291620c 100644 --- a/docs/examples/pi-montecarlo.md +++ b/docs/examples/pi-montecarlo.md @@ -75,8 +75,8 @@ basic.forever(() => { inside = 0 for (let i = 0; i < n; i++) { // generate a point within the square - x = Math.randomInt(r + 1) - y = Math.randomInt(r + 1) + x = Math.randomRange(0, r + 1) + y = Math.randomRange(0, r + 1) // test if the point is within the circle // sqrt(x**2 + y**2) < r ==> x**2 + y**2 < r**2 if (x * x + y * y < r2) { diff --git a/docs/examples/rando.md b/docs/examples/rando.md index 770e3915..009807ee 100644 --- a/docs/examples/rando.md +++ b/docs/examples/rando.md @@ -4,6 +4,6 @@ Generate a random coordinate and display it on the LED screen. ```blocks basic.forever(() => { - led.toggle(Math.randomInt(5), Math.randomInt(5)) + led.toggle(Math.randomRange(0, 5), Math.randomRange(0, 5)) }) ``` \ No newline at end of file diff --git a/docs/examples/stop-watch.md b/docs/examples/stop-watch.md index 0465dd91..ce304bd1 100644 --- a/docs/examples/stop-watch.md +++ b/docs/examples/stop-watch.md @@ -24,7 +24,7 @@ input.onButtonPressed(Button.A, () => { }) basic.forever(() => { if (start) { - led.toggle(Math.randomInt(5), Math.randomInt(5)) + led.toggle(Math.randomRange(0, 5), Math.randomRange(0, 5)) } }) ``` \ No newline at end of file diff --git a/docs/lessons/bop-it/activity.md b/docs/lessons/bop-it/activity.md index 2c173a8f..024bd437 100644 --- a/docs/lessons/bop-it/activity.md +++ b/docs/lessons/bop-it/activity.md @@ -42,7 +42,7 @@ Change the global variable `action` to `math->random(4)` so that we can add a ne ```typescript let action = 0; export function newAction() { - action = Math.randomInt(4) + action = Math.randomRange(0, 4) if (action == 0) { basic.showString("PUSH A", 150) // *** } diff --git a/docs/lessons/bop-it/quiz-answers.md b/docs/lessons/bop-it/quiz-answers.md index e916176c..dba0697e 100644 --- a/docs/lessons/bop-it/quiz-answers.md +++ b/docs/lessons/bop-it/quiz-answers.md @@ -13,13 +13,13 @@ Answer the questions while completing the tutorial. Pay attention to the dialogu ## 1. Write the code that will store the global variable named 'action' and returns a random number between 0 and 2 ```blocks -let action = Math.randomInt(3) +let action = Math.randomRange(0, 3) ``` ## 2. Write the code that will display the string, "PUSH A" if the global variable called 'action' is equal to 0 ```blocks -let action = Math.randomInt(3) +let action = Math.randomRange(0, 3) if (action == 0) { basic.showString("PUSH A", 150) } @@ -29,7 +29,7 @@ if (action == 0) { ```blocks input.onButtonPressed(Button.A, () => { - let action = Math.randomInt(3) + let action = Math.randomRange(0, 3) if (action == 0) { game.addScore(1) } @@ -39,7 +39,7 @@ input.onButtonPressed(Button.A, () => { ## 4. Write the code that will display the string "LOGO DOWN" if the global variable called 'action' is equal to 1 ```blocks -let action = Math.randomInt(3) +let action = Math.randomRange(0, 3) if (action == 1) { basic.showString("LOGO DOWN", 150) } @@ -49,7 +49,7 @@ if (action == 1) { ```blocks input.onLogoDown(() => { - let action = Math.randomInt(3) + let action = Math.randomRange(0, 3) if (action == 1) { game.addScore(1) } @@ -59,7 +59,7 @@ input.onLogoDown(() => { ## 6. Write the code that will display the string "SHAKE" if the global variable called 'action' is equal to 2 ```blocks -let action = Math.randomInt(3) +let action = Math.randomRange(0, 3) if (action == 2) { basic.showString("SHAKE", 150) } @@ -69,7 +69,7 @@ if (action == 2) { ```blocks input.onLogoDown(() => { - let action = Math.randomInt(3) + let action = Math.randomRange(0, 3) if (action == 1) { game.addScore(1) } diff --git a/docs/lessons/catch-the-egg-game.md b/docs/lessons/catch-the-egg-game.md index 783e0717..80e4f839 100644 --- a/docs/lessons/catch-the-egg-game.md +++ b/docs/lessons/catch-the-egg-game.md @@ -29,7 +29,7 @@ basic.pause(300); input.acceleration(Dimension.X); Math.min(0,0); Math.max(0,1); -Math.randomInt(5); +Math.randomRange(0, 5); game.addScore(1); game.score(); game.removeLife(1); diff --git a/docs/lessons/catch-the-egg-game/activity.md b/docs/lessons/catch-the-egg-game/activity.md index 5313290f..a2f34a15 100644 --- a/docs/lessons/catch-the-egg-game/activity.md +++ b/docs/lessons/catch-the-egg-game/activity.md @@ -19,7 +19,7 @@ basic.forever(() => { led.plot(basketX, 4) if (eggY > 4) { eggY = -1 - eggX = Math.randomInt(5) + eggX = Math.randomRange(0, 5) } basic.pause(300) }) @@ -50,7 +50,7 @@ basic.forever(() => { led.plot(basketX1, 4) if (eggY1 > 4) { eggY1 = -1 - eggX1 = Math.randomInt(5) + eggX1 = Math.randomRange(0, 5) } if (eggY1 == 4) { if (basketX1 == eggX1) { @@ -89,7 +89,7 @@ basic.forever(() => { led.plot(basketX2, 4) if (eggY2 > 4) { eggY2 = -1 - eggX2 = Math.randomInt(5) + eggX2 = Math.randomRange(0, 5) } if (eggY2 == 4) { if (basketX2 == eggX2) { @@ -126,7 +126,7 @@ basic.forever(() => { led.plot(basketX3, 4) if (eggY3 > 4) { eggY3 = -1 - eggX3 = Math.randomInt(5) + eggX3 = Math.randomRange(0, 5) } if (eggY3 == 4) { if (basketX3 == eggX3) { diff --git a/docs/lessons/catch-the-egg-game/quiz-answers.md b/docs/lessons/catch-the-egg-game/quiz-answers.md index 5fd9a939..11aed602 100644 --- a/docs/lessons/catch-the-egg-game/quiz-answers.md +++ b/docs/lessons/catch-the-egg-game/quiz-answers.md @@ -52,7 +52,7 @@ let eggX = 2 let eggY = 0 if (eggY > 4) { eggY = -1 - eggX = Math.randomInt(5) + eggX = Math.randomRange(0, 5) } ``` diff --git a/docs/lessons/catch-the-egg-game/tutorial.md b/docs/lessons/catch-the-egg-game/tutorial.md index 4325bc3d..f96211fc 100644 --- a/docs/lessons/catch-the-egg-game/tutorial.md +++ b/docs/lessons/catch-the-egg-game/tutorial.md @@ -22,7 +22,7 @@ basic.forever(() => { led.plot(basketX, 4) if (eggY > 4) { eggY = -1 - eggX = Math.randomInt(5) + eggX = Math.randomRange(0, 5) } basic.pause(300) }) diff --git a/docs/lessons/dice-roll.md b/docs/lessons/dice-roll.md index 6a5a4921..1f1c2244 100644 --- a/docs/lessons/dice-roll.md +++ b/docs/lessons/dice-roll.md @@ -22,7 +22,7 @@ Learn how to use an if statements to run code run code depending on whether a co ```cards input.onGesture(Gesture.Shake, () => {}) let x = 0 -Math.randomInt(3) +Math.randomRange(0, 3) if (true) {} basic.showLeds(` . . . . . diff --git a/docs/lessons/dice-roll/activity.md b/docs/lessons/dice-roll/activity.md index 8e4ad04f..5aff8bfc 100644 --- a/docs/lessons/dice-roll/activity.md +++ b/docs/lessons/dice-roll/activity.md @@ -21,7 +21,7 @@ We need to show a random value from 1 to 6 on our dice. So let's make a local va ```blocks input.onGesture(Gesture.Shake, () => { - let roll = Math.randomInt(6) + let roll = Math.randomRange(0, 6) }) ``` @@ -30,7 +30,7 @@ We need a condition for if **roll** is 5. We will show a `6` if **roll** is 5 be ```blocks input.onGesture(Gesture.Shake, () => { - let roll = Math.randomInt(6); + let roll = Math.randomRange(0, 6); if (roll == 5) { basic.showLeds(` . # . # . @@ -48,7 +48,7 @@ Let's use an `else if` condition for if **roll** is 4. If **roll** is 4 we can s ```blocks input.onGesture(Gesture.Shake, ()=> { - let roll = Math.randomInt(6); + let roll = Math.randomRange(0, 6); if (roll == 5) { basic.showLeds(` . # . # . @@ -75,7 +75,7 @@ Now we need to repeat the same steps for if **roll** is 3. If **roll** is 3 we w ```blocks input.onGesture(Gesture.Shake, () => { - let roll = Math.randomInt(6); + let roll = Math.randomRange(0, 6); if (roll == 5) { basic.showLeds(` . # . # . @@ -108,7 +108,7 @@ Let's also repeat these steps to show the 3, 2, and 1 on the dice. We are almost ```blocks input.onGesture(Gesture.Shake, () => { - let roll = Math.randomInt(6); + let roll = Math.randomRange(0, 6); if (roll == 5) { basic.showLeds(` . # . # . diff --git a/docs/lessons/dice-roll/challenges.md b/docs/lessons/dice-roll/challenges.md index 31c2ed1f..9f02bbdd 100644 --- a/docs/lessons/dice-roll/challenges.md +++ b/docs/lessons/dice-roll/challenges.md @@ -8,7 +8,7 @@ Complete the following [guided tutorial](/lessons/dice-roll/activity), your code ```blocks input.onGesture(Gesture.Shake, () => { - let roll = Math.randomInt(6); + let roll = Math.randomRange(0, 6); if (roll == 5) { basic.showLeds(` . # . # . @@ -67,7 +67,7 @@ Modify the line of code with `pick random` so that only number 1-4 can appear on ```blocks input.onGesture(Gesture.Shake, () => { - let roll = Math.randomInt(4); + let roll = Math.randomRange(0, 4); if (roll == 5) { basic.showLeds(` . # . # . @@ -125,7 +125,7 @@ Let's make a trick dice! Modify the line of code with `pick random` so that only ```blocks input.onGesture(Gesture.Shake, () => { - let roll = Math.randomInt(4) + 2; + let roll = Math.randomRange(0, 4) + 2; if (roll == 5) { basic.showLeds(` . # . # . diff --git a/docs/lessons/dice-roll/quiz-answers.md b/docs/lessons/dice-roll/quiz-answers.md index 0a30dbcd..2afe6b03 100644 --- a/docs/lessons/dice-roll/quiz-answers.md +++ b/docs/lessons/dice-roll/quiz-answers.md @@ -9,7 +9,7 @@ These are the answers to the [dice roll quiz](/lessons/dice-roll/quiz).
```blocks -let roll = Math.randomInt(6) +let roll = Math.randomRange(0, 6) ``` ## 2. If the variable "roll" equals 5, write the code that will plot the image below @@ -19,7 +19,7 @@ let roll = Math.randomInt(6)
```blocks -let roll = Math.randomInt(6) +let roll = Math.randomRange(0, 6) if (roll == 5) { basic.showLeds(` . # . # . @@ -39,7 +39,7 @@ if (roll == 5) { ```blocks -let roll = Math.randomInt(6) +let roll = Math.randomRange(0, 6) if (roll == 5) { basic.showLeds(` . # . # . @@ -68,7 +68,7 @@ Note: students are only required to write the bottom half of this answer, starti
```blocks -let roll = Math.randomInt(6) +let roll = Math.randomRange(0, 6) if (roll == 4) { basic.showLeds(` . . . . . @@ -97,7 +97,7 @@ Note: students are only required to write the bottom half of this answer, starti
```blocks -let roll = Math.randomInt(6) +let roll = Math.randomRange(0, 6) if (roll == 3) { basic.showLeds(` . . . . . diff --git a/docs/lessons/guess-the-number.md b/docs/lessons/guess-the-number.md index bbd3cf7a..6c94cb4f 100644 --- a/docs/lessons/guess-the-number.md +++ b/docs/lessons/guess-the-number.md @@ -24,7 +24,7 @@ Learn how to create numbers randomly by using the input of the @boardname@. We w input.onButtonPressed(Button.A, () => {}) let x = 0 basic.showNumber(0) -Math.randomInt(3) +Math.randomRange(0, 3) basic.clearScreen() ``` diff --git a/docs/lessons/guess-the-number/activity.md b/docs/lessons/guess-the-number/activity.md index 1295167a..c2d76b55 100644 --- a/docs/lessons/guess-the-number/activity.md +++ b/docs/lessons/guess-the-number/activity.md @@ -21,7 +21,7 @@ Create a local variable of type number `x` and set it to a random number using ` ```blocks input.onButtonPressed(Button.A, () => { - let x = Math.randomInt(10) + let x = Math.randomRange(0, 10) }) ``` @@ -31,7 +31,7 @@ Show the random number on the screen. ```blocks input.onButtonPressed(Button.A, () => { - let x = Math.randomInt(10) + let x = Math.randomRange(0, 10) basic.showNumber(x) }) diff --git a/docs/lessons/guess-the-number/challenges.md b/docs/lessons/guess-the-number/challenges.md index 402cd6b7..5c03ac9c 100644 --- a/docs/lessons/guess-the-number/challenges.md +++ b/docs/lessons/guess-the-number/challenges.md @@ -8,7 +8,7 @@ Complete the following [guided tutorial](/lessons/guess-the-number/activity), an ```blocks input.onButtonPressed(Button.A, () => { - let x = Math.randomInt(9) + let x = Math.randomRange(0, 9) basic.showNumber(x) }) ``` @@ -19,7 +19,7 @@ When button `B` is pressed, we want to clear the screen. This will make it so us ```blocks input.onButtonPressed(Button.A, () => { - let x = Math.randomInt(9) + let x = Math.randomRange(0, 9) basic.showNumber(x) }) input.onButtonPressed(Button.B, () => { diff --git a/docs/lessons/guess-the-number/quiz-answers.md b/docs/lessons/guess-the-number/quiz-answers.md index e0bdd5e1..0f8bd5e9 100644 --- a/docs/lessons/guess-the-number/quiz-answers.md +++ b/docs/lessons/guess-the-number/quiz-answers.md @@ -24,14 +24,14 @@ input.onButtonPressed(Button.A, () => { ```blocks -let randomNumber = Math.randomInt(10) +let randomNumber = Math.randomRange(0, 10) ``` ## 4. If the rectangle below represents the @boardname@, shade the areas that will be displayed. Explain why that particular area is shaded. ```blocks -let randomNumber = Math.randomInt(10) +let randomNumber = Math.randomRange(0, 10) ``` diff --git a/docs/lessons/guess-the-number/quiz.md b/docs/lessons/guess-the-number/quiz.md index d2f46f98..93e7478d 100644 --- a/docs/lessons/guess-the-number/quiz.md +++ b/docs/lessons/guess-the-number/quiz.md @@ -25,7 +25,7 @@ Answer the questions while completing the tutorial. Pay attention to the dialogu ## 4. Draw the area that could be lit based on the code below. Explain why you chose to draw that number. ```blocks -let randomNumber = Math.randomInt(10) +let randomNumber = Math.randomRange(0, 10) basic.showNumber(randomNumber, 150) ``` diff --git a/docs/lessons/guess-the-number/tutorial.md b/docs/lessons/guess-the-number/tutorial.md index 2da7e82d..8b81cf23 100644 --- a/docs/lessons/guess-the-number/tutorial.md +++ b/docs/lessons/guess-the-number/tutorial.md @@ -16,7 +16,7 @@ The blocks have been shuffled! Put them back together so that... ```shuffle input.onButtonPressed(Button.A, () => { - let x = Math.randomInt(10) + let x = Math.randomRange(0, 10) basic.showNumber(x) }) ``` diff --git a/docs/lessons/headbands/activity.md b/docs/lessons/headbands/activity.md index 9e38ba48..213a82b2 100644 --- a/docs/lessons/headbands/activity.md +++ b/docs/lessons/headbands/activity.md @@ -12,7 +12,7 @@ coll.push("night") coll.push("cat") coll.push("cow") input.onLogoUp(() => { - let index = Math.randomInt(coll.length) + let index = Math.randomRange(0, coll.length) let word = coll[index] basic.showString(word, 150) }) @@ -34,7 +34,7 @@ coll.push("night") coll.push("cat") coll.push("cow") input.onLogoUp(() => { - let index = Math.randomInt(coll.length) + let index = Math.randomRange(0, coll.length) let word = coll[index] basic.showString(word, 150) }) @@ -64,7 +64,7 @@ coll.push("sun") coll.push("car") coll.push("ant") input.onLogoUp(() => { - let index = Math.randomInt(coll.length) + let index = Math.randomRange(0, coll.length) let word = coll[index] basic.showString(word, 150) }) diff --git a/docs/lessons/headbands/quiz-answers.md b/docs/lessons/headbands/quiz-answers.md index 58f3d418..4d21d2e0 100644 --- a/docs/lessons/headbands/quiz-answers.md +++ b/docs/lessons/headbands/quiz-answers.md @@ -76,7 +76,7 @@ coll.push("cow") ```blocks let coll: string[] = [] -let index = Math.randomInt(coll.length) +let index = Math.randomRange(0, coll.length) let word = coll[index] ``` diff --git a/docs/lessons/hero/activity.md b/docs/lessons/hero/activity.md index 0137122b..09597a21 100644 --- a/docs/lessons/hero/activity.md +++ b/docs/lessons/hero/activity.md @@ -193,8 +193,8 @@ while (true) { } if (hero.isTouching(food)) { game.addScore(1); - food.set(LedSpriteProperty.X, Math.randomInt(5)); - food.set(LedSpriteProperty.Y, Math.randomInt(5)); + food.set(LedSpriteProperty.X, Math.randomRange(0, 5)); + food.set(LedSpriteProperty.Y, Math.randomRange(0, 5)); } } @@ -241,8 +241,8 @@ while (true) { } if (hero.isTouching(food)) { game.addScore(1); - food.set(LedSpriteProperty.X, Math.randomInt(5)); - food.set(LedSpriteProperty.Y, Math.randomInt(5)); + food.set(LedSpriteProperty.X, Math.randomRange(0, 5)); + food.set(LedSpriteProperty.Y, Math.randomRange(0, 5)); if (food.get(LedSpriteProperty.X) < 2 && food.get(LedSpriteProperty.Y) < 2) { ghost.set(LedSpriteProperty.X, 4); ghost.set(LedSpriteProperty.Y, 4); diff --git a/docs/lessons/love-meter.md b/docs/lessons/love-meter.md index eaee38ff..01f8e82d 100644 --- a/docs/lessons/love-meter.md +++ b/docs/lessons/love-meter.md @@ -24,7 +24,7 @@ Learn how to use the **pin pressed**, `on pin pressed` to run code when the user if (true) {} input.onPinPressed(TouchPin.P0, () => {}) let x = 0 -Math.randomInt(3) +Math.randomRange(0, 3) basic.showNumber(0) basic.pause(100) ``` diff --git a/docs/lessons/love-meter/activity.md b/docs/lessons/love-meter/activity.md index 860f1a3b..0ed90df1 100644 --- a/docs/lessons/love-meter/activity.md +++ b/docs/lessons/love-meter/activity.md @@ -23,7 +23,7 @@ We are going to create a meter that displays a random number from *0* to *10*. W ```blocks input.onPinPressed(TouchPin.P0, () => { - let x = Math.randomInt(10) + let x = Math.randomRange(0, 10) }) ``` @@ -33,7 +33,7 @@ Finally, let's show that number on the @boardname@. You are registering an event ```blocks input.onPinPressed(TouchPin.P0, () => { - let x = Math.randomInt(10) + let x = Math.randomRange(0, 10) basic.showNumber(x) }) diff --git a/docs/lessons/love-meter/challenges.md b/docs/lessons/love-meter/challenges.md index df5ded81..efe1fcf0 100644 --- a/docs/lessons/love-meter/challenges.md +++ b/docs/lessons/love-meter/challenges.md @@ -8,7 +8,7 @@ You should work on these challenges after the following the [love meter activity ```blocks input.onPinPressed(TouchPin.P0, () => { - let x = Math.randomInt(10) + let x = Math.randomRange(0, 10) basic.showNumber(x) }) @@ -21,7 +21,7 @@ Add a pause of 3000 milliseconds (3 seconds) after showing the number so that th ```blocks input.onPinPressed(TouchPin.P0, () => { - let x = Math.randomInt(10) + let x = Math.randomRange(0, 10) basic.showNumber(x) basic.pause(3000) }) @@ -34,7 +34,7 @@ If the rating **x** is between *0* and *3* (strictly less than *4*), display the ```blocks input.onPinPressed(TouchPin.P0, () => { - let x = Math.randomInt(10) + let x = Math.randomRange(0, 10) basic.showNumber(x) basic.pause(3000) if (x < 4) { @@ -49,7 +49,7 @@ input.onPinPressed(TouchPin.P0, () => { ```blocks input.onPinPressed(TouchPin.P0, () => { - let x = Math.randomInt(10) + let x = Math.randomRange(0, 10) basic.showNumber(x) basic.pause(3000) if (x < 4) { diff --git a/docs/lessons/love-meter/quiz-answers.md b/docs/lessons/love-meter/quiz-answers.md index c0b4cfb0..6dc8a33b 100644 --- a/docs/lessons/love-meter/quiz-answers.md +++ b/docs/lessons/love-meter/quiz-answers.md @@ -23,7 +23,7 @@ input.onPinPressed(TouchPin.P0, () => { ## 3. What does this line of code doing? ```blocks -let x = Math.randomInt(9) +let x = Math.randomRange(0, 9) ``` diff --git a/docs/lessons/love-meter/quiz.md b/docs/lessons/love-meter/quiz.md index 6add8c1f..6553fc7c 100644 --- a/docs/lessons/love-meter/quiz.md +++ b/docs/lessons/love-meter/quiz.md @@ -19,7 +19,7 @@ Answer the questions below while completing the activity. Pay attention to the d ## 3. Describe what this line of code does? ```blocks -let x = Math.randomInt(9) +let x = Math.randomRange(0, 9) ``` diff --git a/docs/lessons/magic-8.md b/docs/lessons/magic-8.md index 04723b9a..b3b70861 100644 --- a/docs/lessons/magic-8.md +++ b/docs/lessons/magic-8.md @@ -22,7 +22,7 @@ Learn how to creating **conditionals**, `if condition do` to conditionally run c ```cards if (true) {} -Math.randomInt(3) +Math.randomRange(0, 3) input.onGesture(Gesture.Shake, () => {}) basic.showNumber(7) basic.clearScreen() diff --git a/docs/lessons/magic-8/activity.md b/docs/lessons/magic-8/activity.md index 62a74e86..af1aa350 100644 --- a/docs/lessons/magic-8/activity.md +++ b/docs/lessons/magic-8/activity.md @@ -34,7 +34,7 @@ basic.showString("ASK A QUESTION") basic.showNumber(8) input.onGesture(Gesture.Shake, () => { basic.clearScreen() - let randomNumber = Math.randomInt(3) + let randomNumber = Math.randomRange(0, 3) }); ``` @@ -47,7 +47,7 @@ basic.showString("ASK A QUESTION") basic.showNumber(8) input.onGesture(Gesture.Shake, () => { basic.clearScreen(); - let randomNumber = Math.randomInt(3); + let randomNumber = Math.randomRange(0, 3); if (randomNumber == 2) { basic.showString("YES"); } @@ -63,7 +63,7 @@ basic.showString("ASK A QUESTION") basic.showNumber(8) input.onGesture(Gesture.Shake, () => { basic.clearScreen() - let randomNumber = Math.randomInt(3) + let randomNumber = Math.randomRange(0, 3) if (randomNumber == 2) { basic.showString("YES") } else if (randomNumber == 1) { @@ -79,7 +79,7 @@ basic.showString("ASK A QUESTION") basic.showNumber(8) input.onGesture(Gesture.Shake, () => { basic.clearScreen() - let randomNumber = Math.randomInt(3) + let randomNumber = Math.randomRange(0, 3) if (randomNumber == 2) { basic.showString("YES") } else if (randomNumber == 1) { @@ -101,7 +101,7 @@ basic.showString("ASK A QUESTION") basic.showNumber(8) input.onGesture(Gesture.Shake, () => { basic.clearScreen() - let randomNumber = Math.randomInt(3) + let randomNumber = Math.randomRange(0, 3) if (randomNumber == 2) { basic.showString("YES") } else if (randomNumber == 1) { diff --git a/docs/lessons/magic-8/challenges.md b/docs/lessons/magic-8/challenges.md index ed102a87..7f6ef39a 100644 --- a/docs/lessons/magic-8/challenges.md +++ b/docs/lessons/magic-8/challenges.md @@ -11,7 +11,7 @@ basic.showString("ASK A QUESTION") basic.showNumber(8) input.onGesture(Gesture.Shake, () => { basic.clearScreen() - let randomNumber = Math.randomInt(2) + let randomNumber = Math.randomRange(0, 2) if (randomNumber == 2) { basic.showString("YES") } else if (randomNumber == 1) { @@ -35,7 +35,7 @@ basic.showString("ASK A QUESTION") basic.showNumber(8) input.onGesture(Gesture.Shake, () => { basic.clearScreen() - let randomNumber = Math.randomInt(4) + let randomNumber = Math.randomRange(0, 4) if (randomNumber == 2) { basic.showString("YES") } else if (randomNumber == 1) { @@ -59,7 +59,7 @@ basic.showString("ASK A QUESTION") basic.showNumber(8) input.onGesture(Gesture.Shake, () => { basic.clearScreen() - let randomNumber = Math.randomInt(4) + let randomNumber = Math.randomRange(0, 4) if (randomNumber == 3) { basic.showString("TRY AGAIN") } else if (randomNumber == 2) { @@ -82,7 +82,7 @@ basic.showString("ASK A QUESTION") basic.showNumber(8) input.onGesture(Gesture.Shake, () => { basic.clearScreen() - let randomNumber = Math.randomInt(4) + let randomNumber = Math.randomRange(0, 4) if (randomNumber == 4) { basic.showString("DEFINATELY") } else if (randomNumber == 3) { diff --git a/docs/lessons/magic-8/quiz-answers.md b/docs/lessons/magic-8/quiz-answers.md index d05bba68..d7efc80b 100644 --- a/docs/lessons/magic-8/quiz-answers.md +++ b/docs/lessons/magic-8/quiz-answers.md @@ -19,13 +19,13 @@ An if statement will conditionally run code depending on whether or not a condit ## 2. Create a Variable called ``x`` and assign it to a random number between 0 and 2. ```blocks -let x = Math.randomInt(3) +let x = Math.randomRange(0, 3) ``` ## 3. Write the 'if statement' to check if ``x`` is equal to 2. Inside the 'if statement', display the string "Yes". ```blocks -let x = Math.randomInt(3) +let x = Math.randomRange(0, 3) if (x == 2) { basic.showString("Yes", 150) } @@ -34,7 +34,7 @@ if (x == 2) { ## 4. Write the 'if statement' to check if ``x`` is equal to 1. Inside the 'if statement', display the string "No." ```blocks -let x = Math.randomInt(3) +let x = Math.randomRange(0, 3) if (x == 2) { basic.showString("Yes", 150) } else if (x == 1) { @@ -45,7 +45,7 @@ if (x == 2) { ## 5. Write the code to display the string "I don't know" if the Variable ``x`` is neither 2 nor 1. ```blocks -let x = Math.randomInt(3) +let x = Math.randomRange(0, 3) if (x == 2) { basic.showString("Yes", 150) } else if (x == 1) { diff --git a/docs/lessons/magic-8/tutorial.md b/docs/lessons/magic-8/tutorial.md index f3f6fcbf..2cfde83b 100644 --- a/docs/lessons/magic-8/tutorial.md +++ b/docs/lessons/magic-8/tutorial.md @@ -15,7 +15,7 @@ The blocks have been shuffled! Put them back together so that... ```shuffle basic.showString("ASK A QUESTION") input.onGesture(Gesture.Shake, () => { - let randomNumber = Math.randomInt(3) + let randomNumber = Math.randomRange(0, 3) if (randomNumber == 2) { basic.showString("YES") } else if (randomNumber == 1) { diff --git a/docs/lessons/spinner.md b/docs/lessons/spinner.md index 7ec51cd1..68ad2a7c 100644 --- a/docs/lessons/spinner.md +++ b/docs/lessons/spinner.md @@ -25,7 +25,7 @@ Learn how to use an if statement to run code run code depending on whether a con if (true) {} let x = 0 input.onGesture(Gesture.Shake, () => {}) -Math.randomInt(3) +Math.randomRange(0, 3) basic.showLeds(` . . . . . . . . . . diff --git a/docs/lessons/spinner/activity.md b/docs/lessons/spinner/activity.md index 1535a554..fea77ed6 100644 --- a/docs/lessons/spinner/activity.md +++ b/docs/lessons/spinner/activity.md @@ -22,7 +22,7 @@ Now let's randomly generate a number from 0 to 3 so that we can randomly display ```blocks input.onGesture(Gesture.Shake, () => { - let randomArrow = Math.randomInt(4) + let randomArrow = Math.randomRange(0, 4) if (randomArrow == 3) { basic.showLeds(` . . # . . @@ -41,7 +41,7 @@ Now let's handle each of the cases by displaying the appropriate arrow. (Let's d ```blocks input.onGesture(Gesture.Shake, () => { - let randomArrow = Math.randomInt(4) + let randomArrow = Math.randomRange(0, 4) if (randomArrow == 3) { basic.showLeds(` . . # . . @@ -69,7 +69,7 @@ Now let's handle the rest of the cases for `random arrow`. ```blocks input.onGesture(Gesture.Shake, () => { - let randomArrow = Math.randomInt(4) + let randomArrow = Math.randomRange(0, 4) if (randomArrow == 3) { basic.showLeds(` . . # . . diff --git a/docs/lessons/spinner/challenges.md b/docs/lessons/spinner/challenges.md index 62d22341..e45c3107 100644 --- a/docs/lessons/spinner/challenges.md +++ b/docs/lessons/spinner/challenges.md @@ -8,7 +8,7 @@ Complete the following [guided tutorial](/lessons/spinner/activity), your code s ```blocks input.onGesture(Gesture.Shake, () => { - let randomArrow = Math.randomInt(4) + let randomArrow = Math.randomRange(0, 4) if (randomArrow == 3) { basic.showLeds(` . . # . . @@ -46,7 +46,7 @@ Modify the random number generator so that it can include new arrows we will cre ```blocks input.onGesture(Gesture.Shake, () => { - let randomArrow = Math.randomInt(8) + let randomArrow = Math.randomRange(0, 8) if (randomArrow == 3) { basic.showLeds(` . . # . . @@ -89,7 +89,7 @@ Let's add more arrows that point diagonally. ```blocks input.onGesture(Gesture.Shake, () => { - let randomArrow = Math.randomInt(8) + let randomArrow = Math.randomRange(0, 8) if (randomArrow == 7) { basic.showLeds(` . . # . . diff --git a/docs/lessons/spinner/quiz-answers.md b/docs/lessons/spinner/quiz-answers.md index a3650bf0..c2d29720 100644 --- a/docs/lessons/spinner/quiz-answers.md +++ b/docs/lessons/spinner/quiz-answers.md @@ -15,7 +15,7 @@ Answer the questions while completing the tutorial. Pay attention to the dialogu
```blocks -let randomArrow = Math.randomInt(4) +let randomArrow = Math.randomRange(0, 4) ``` ## 2. Write the if statement that will display this down arrow from your code. Hint- This occurs if the local variable 'random arrow' returns 1. @@ -25,7 +25,7 @@ let randomArrow = Math.randomInt(4)
```blocks -let randomArrow = Math.randomInt(4); +let randomArrow = Math.randomRange(0, 4); if (randomArrow == 1) { basic.showLeds(` . . # . . @@ -44,7 +44,7 @@ if (randomArrow == 1) {
```blocks -let randomArrow = Math.randomInt(4); +let randomArrow = Math.randomRange(0, 4); if (randomArrow == 2) { basic.showLeds(` . . # . . diff --git a/docs/lessons/truth-or-dare.md b/docs/lessons/truth-or-dare.md index 449ffb7d..de9e9bb1 100644 --- a/docs/lessons/truth-or-dare.md +++ b/docs/lessons/truth-or-dare.md @@ -32,7 +32,7 @@ basic.showLeds(` `) input.onButtonPressed(Button.A, () => {}) let x = 0 -Math.randomInt(3) +Math.randomRange(0, 3) if (true) {} basic.showString("Hello!") ``` diff --git a/docs/lessons/truth-or-dare/activity.md b/docs/lessons/truth-or-dare/activity.md index 7e21f4eb..99a49246 100644 --- a/docs/lessons/truth-or-dare/activity.md +++ b/docs/lessons/truth-or-dare/activity.md @@ -34,7 +34,7 @@ basic.showLeds(` . . # . . `) input.onButtonPressed(Button.A, () => { - let random = Math.randomInt(2) + let random = Math.randomRange(0, 2) }) ``` @@ -49,7 +49,7 @@ basic.showLeds(` . . # . . `) input.onButtonPressed(Button.A, () => { - let random = Math.randomInt(2) + let random = Math.randomRange(0, 2) if (random == 0) { basic.showString("TRUTH") } else { @@ -71,7 +71,7 @@ basic.showLeds(` . . # . . `) input.onButtonPressed(Button.A, () => { - let random = Math.randomInt(2) + let random = Math.randomRange(0, 2) if (random == 0) { basic.showString("TRUTH") } else { diff --git a/docs/lessons/truth-or-dare/challenges.md b/docs/lessons/truth-or-dare/challenges.md index ecef469d..97586d60 100644 --- a/docs/lessons/truth-or-dare/challenges.md +++ b/docs/lessons/truth-or-dare/challenges.md @@ -16,7 +16,7 @@ basic.showLeds(` . . # . . `) input.onButtonPressed(Button.A, () => { - let random = Math.randomInt(2) + let random = Math.randomRange(0, 2) if (random == 0) { basic.showString("TRUTH") } else { @@ -45,7 +45,7 @@ basic.showLeds(` . . # . . `) input.onButtonPressed(Button.A, () => { - let random = Math.randomInt(3) + let random = Math.randomRange(0, 3) if (random == 0) { basic.showString("TRUTH") } else { @@ -75,7 +75,7 @@ basic.showLeds(` . . # . . `) input.onButtonPressed(Button.A, () => { - let random = Math.randomInt(2) + let random = Math.randomRange(0, 2) if (random == 1) { basic.showString("TRUTH") } else if (random == 0) { diff --git a/docs/lessons/truth-or-dare/quiz-answers.md b/docs/lessons/truth-or-dare/quiz-answers.md index ff221dc7..850de656 100644 --- a/docs/lessons/truth-or-dare/quiz-answers.md +++ b/docs/lessons/truth-or-dare/quiz-answers.md @@ -7,13 +7,13 @@ This is the answer key for the [truth or dare quiz](/lessons/truth-or-dare/quiz) ## 1. Write the code that will randomly return 0 through 3 and stores the value inside a local variable called 'random'. ```blocks -let random = Math.randomInt(4) +let random = Math.randomRange(0, 4) ``` ## 2. Write an if statement that will display the message "TRUTH" on the @boardname@ if the local variable 'random' equals 0. ```blocks -let random = Math.randomInt(4) +let random = Math.randomRange(0, 4) if (random == 0) { basic.showString("TRUTH", 150) } diff --git a/docs/lessons/truth-or-dare/tutorial.md b/docs/lessons/truth-or-dare/tutorial.md index 4d3af167..19440983 100644 --- a/docs/lessons/truth-or-dare/tutorial.md +++ b/docs/lessons/truth-or-dare/tutorial.md @@ -27,7 +27,7 @@ basic.showLeds(` . . # . . `) input.onButtonPressed(Button.A, () => { - let random = Math.randomInt(2) + let random = Math.randomRange(0, 2) if (random == 0) { basic.showString("TRUTH") } else { @@ -53,7 +53,7 @@ basic.showLeds(` . . # . . . . # . . `); -Math.randomInt(2); +Math.randomRange(0, 2); basic.showString("TRUTH"); if (true) {} else {} "TRUTH"; diff --git a/docs/projects/infection.md b/docs/projects/infection.md index 61cdc66a..ab9fc9b4 100644 --- a/docs/projects/infection.md +++ b/docs/projects/infection.md @@ -257,7 +257,7 @@ input.onButtonPressed(Button.AB, () => { // launch game if (state == GameState.Pairing) { // pick 1 player and infect him - patientZero = players[Math.randomInt(players.length)]; + patientZero = players[Math.randomRange(0, players.length)]; while (patientZero.health == HealthState.Healthy) { radio.sendValue("infect", patientZero.id); basic.pause(100); @@ -333,7 +333,7 @@ radio.onDataPacketReceived(({ time, receivedNumber, receivedString, signal, seri if (health == HealthState.Healthy && receivedString == "transmit") { serial.writeLine(`signal: ${signal}`); if (signal > RSSI && - Math.randomInt(100) > TRANSMISSIONPROB) { + Math.randomRange(0, 100) > TRANSMISSIONPROB) { infectedBy = receivedNumber; infectedTime = input.runningTime(); health = HealthState.Incubating; diff --git a/docs/projects/love-meter.md b/docs/projects/love-meter.md index 50f21b14..eb2a462d 100644 --- a/docs/projects/love-meter.md +++ b/docs/projects/love-meter.md @@ -18,7 +18,7 @@ show a random number from 0 to 100 when pin ``P0`` is pressed. ```blocks input.onPinPressed(TouchPin.P0, () => { - basic.showNumber(Math.randomInt(101)); + basic.showNumber(Math.randomRange(0, 101)); }); ``` @@ -29,7 +29,7 @@ Show ``"LOVE METER"`` on the screen when the @boardname@ starts. ```blocks basic.showString("LOVE METER"); input.onPinPressed(TouchPin.P0, () => { - basic.showNumber(Math.randomInt(101)); + basic.showNumber(Math.randomRange(0, 101)); }); ``` diff --git a/docs/projects/reaction-time/code.md b/docs/projects/reaction-time/code.md index 4d88eeba..899d8861 100644 --- a/docs/projects/reaction-time/code.md +++ b/docs/projects/reaction-time/code.md @@ -125,7 +125,7 @@ input.onPinPressed(TouchPin.P0, () => { basic.clearScreen() running = false false_start = false - basic.pause(1000 + Math.randomInt(2000)) + basic.pause(1000 + Math.randomRange(0, 2000)) }) input.onPinPressed(TouchPin.P1, () => { @@ -155,13 +155,13 @@ input.onPinPressed(TouchPin.P0, () => { basic.clearScreen() running = false false_start = false - basic.pause(1000 + Math.randomInt(2000)) + basic.pause(1000 + Math.randomRange(0, 2000)) if (!(false_start)) { start = input.runningTime() running = true led.stopAnimation() basic.clearScreen() - led.plot(Math.randomInt(5), Math.randomInt(5)) + led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5)) } }) running = false @@ -214,13 +214,13 @@ input.onPinPressed(TouchPin.P0, () => { basic.clearScreen() running = false false_start = false - basic.pause(1000 + Math.randomInt(2000)) + basic.pause(1000 + Math.randomRange(0, 2000)) if (!(false_start)) { start = input.runningTime() running = true led.stopAnimation() basic.clearScreen() - led.plot(Math.randomInt(5), Math.randomInt(5)) + led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5)) } }) running = false @@ -247,13 +247,13 @@ input.onPinPressed(TouchPin.P0, () => { basic.clearScreen() running = false false_start = false - basic.pause(1000 + Math.randomInt(2000)) + basic.pause(1000 + Math.randomRange(0, 2000)) if (!(false_start)) { start = input.runningTime() running = true led.stopAnimation() basic.clearScreen() - led.plot(Math.randomInt(5), Math.randomInt(5)) + led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5)) } }) input.onPinPressed(TouchPin.P1, () => { diff --git a/docs/projects/rock-paper-scissors/code.md b/docs/projects/rock-paper-scissors/code.md index 2943238e..dbeeb292 100644 --- a/docs/projects/rock-paper-scissors/code.md +++ b/docs/projects/rock-paper-scissors/code.md @@ -22,7 +22,7 @@ rock, paper, and scissors are the tools you use to challenge your friends!) ```blocks let tool = 0; input.onGesture(Gesture.Shake, () => { - tool = Math.randomInt(3) + tool = Math.randomRange(0, 3) }) ``` @@ -37,7 +37,7 @@ check whether ``tool`` is equal to ``0``. ```blocks let tool = 0; input.onGesture(Gesture.Shake, () => { - let tool = Math.randomInt(3) + let tool = Math.randomRange(0, 3) if (tool == 0) { } }) @@ -51,7 +51,7 @@ picture of a piece of paper. ```blocks let tool = 0; input.onGesture(Gesture.Shake, () => { - let tool = Math.randomInt(3) + let tool = Math.randomRange(0, 3) if (tool == 0) { basic.showLeds(` # # # # # @@ -74,7 +74,7 @@ Click on the gearwheel icon to open up the ``if`` editor; then drag and drop an ```blocks let tool = 0; input.onGesture(Gesture.Shake, () => { - let tool = Math.randomInt(3) + let tool = Math.randomRange(0, 3) if (tool == 0) { basic.showLeds(` # # # # # @@ -95,7 +95,7 @@ Place a ``||basic:show leds||`` block under the else if and draw a **rock** imag ```blocks let tool = 0; input.onGesture(Gesture.Shake, () => { - let tool = Math.randomInt(3) + let tool = Math.randomRange(0, 3) if (tool == 0) { basic.showLeds(` # # # # # @@ -126,7 +126,7 @@ That's why you can use an ``else`` instead of an ``else if``. ```blocks let tool = 0; input.onGesture(Gesture.Shake, () => { - let tool = Math.randomInt(3) + let tool = Math.randomRange(0, 3) if (tool == 0) { basic.showLeds(` # # # # # diff --git a/docs/projects/rps-teams.md b/docs/projects/rps-teams.md index f85938ef..c8a53442 100644 --- a/docs/projects/rps-teams.md +++ b/docs/projects/rps-teams.md @@ -26,7 +26,7 @@ Let's start out with the code from the original game. The basic version picks on ```blocks let tool = 0 input.onGesture(Gesture.Shake, () => { - tool = Math.randomInt(3) + tool = Math.randomRange(0, 3) if (tool == 0) { basic.showIcon(IconNames.SmallSquare) } else if (tool == 1) { @@ -44,7 +44,7 @@ input.onGesture(Gesture.Shake, () => { ```blocks let tool = 0 input.onGesture(Gesture.Shake, () => { - tool = Math.randomInt(3) + tool = Math.randomRange(0, 3) }) basic.forever(() => { @@ -67,7 +67,7 @@ We also set the radio group and send the device serial number (a number that uni ```blocks let tool = 0 input.onGesture(Gesture.Shake, () => { - tool = Math.randomInt(3) + tool = Math.randomRange(0, 3) }) basic.forever(() => { @@ -154,7 +154,7 @@ What if some of the other players leave the game? They would stop broadcasting t ```block input.onGesture(Gesture.Shake, () => { let players: number[] = [0] - let tool = Math.randomInt(3) + let tool = Math.randomRange(0, 3) }) ``` @@ -185,7 +185,7 @@ let match = false let players: number[] = [] input.onGesture(Gesture.Shake, () => { players = [0] - tool = Math.randomInt(3) + tool = Math.randomRange(0, 3) }) radio.onDataPacketReceived( ({ receivedNumber, serial: serialNumber }) => { match = tool == receivedNumber diff --git a/docs/projects/salute.md b/docs/projects/salute.md index 9c74fc02..ca4dd6f2 100644 --- a/docs/projects/salute.md +++ b/docs/projects/salute.md @@ -38,7 +38,7 @@ Choose a random number between 0 and 9. ```blocks let randomNbr = 0 input.onGesture(Gesture.ScreenUp, () => { - randomNbr = Math.randomInt(10) + randomNbr = Math.randomRange(0, 10) basic.showNumber(randomNbr) }) ``` @@ -50,7 +50,7 @@ let randomNbr = 0 input.onGesture(Gesture.ScreenUp, () => { randomNbr = 0 while (randomNbr < 1) { - randomNbr = Math.randomInt(10) + randomNbr = Math.randomRange(0, 10) } basic.showNumber(randomNbr) }) diff --git a/docs/reference/input/on-button-pressed.md b/docs/reference/input/on-button-pressed.md index a34873cb..fe5bc1f1 100644 --- a/docs/reference/input/on-button-pressed.md +++ b/docs/reference/input/on-button-pressed.md @@ -32,7 +32,7 @@ This example shows a number from 1 to 6 when you press the `B` button. ```blocks input.onButtonPressed(Button.B, () => { - let dice = Math.randomInt(6) + 1 + let dice = Math.randomRange(0, 6) + 1 basic.showNumber(dice) }) ``` diff --git a/docs/reference/input/on-gesture.md b/docs/reference/input/on-gesture.md index 20e87ad1..7725d513 100644 --- a/docs/reference/input/on-gesture.md +++ b/docs/reference/input/on-gesture.md @@ -19,7 +19,7 @@ This program shows a number from `0` to `9` when you shake the @boardname@. ```blocks input.onGesture(Gesture.Shake,() => { - let x = Math.randomInt(10) + let x = Math.randomRange(0, 10) basic.showNumber(x, 100) }) ``` diff --git a/docs/tutorials/getting-started.md b/docs/tutorials/getting-started.md index b5e538f6..03425a49 100644 --- a/docs/tutorials/getting-started.md +++ b/docs/tutorials/getting-started.md @@ -58,7 +58,7 @@ on the screen. ```block input.onGesture(Gesture.Shake, () => { - basic.showNumber(Math.randomInt(7)) + basic.showNumber(Math.randomRange(0, 7)) }) ``` diff --git a/docs/tutorials/hour-of-code/rock-paper-scissors.md b/docs/tutorials/hour-of-code/rock-paper-scissors.md index ae0eb61c..8e42aca2 100644 --- a/docs/tutorials/hour-of-code/rock-paper-scissors.md +++ b/docs/tutorials/hour-of-code/rock-paper-scissors.md @@ -22,7 +22,7 @@ rock, paper, and scissors are the tools you use to challenge your friends!) ```blocks let tool = 0; input.onGesture(Gesture.Shake, () => { - tool = Math.randomInt(3) + tool = Math.randomRange(0, 3) }) ``` @@ -36,7 +36,7 @@ check whether ``tool`` is equal to ``0``. ```blocks let tool = 0; input.onGesture(Gesture.Shake, () => { - let tool = Math.randomInt(3) + let tool = Math.randomRange(0, 3) if (tool == 0) { } }) @@ -50,7 +50,7 @@ picture of a piece of paper. ```blocks let tool = 0; input.onGesture(Gesture.Shake, () => { - let tool = Math.randomInt(3) + let tool = Math.randomRange(0, 3) if (tool == 0) { basic.showLeds(` # # # # # @@ -73,7 +73,7 @@ Click on the gearwheel icon to open up the ``if`` editor; then drag and drop an ```blocks let tool = 0; input.onGesture(Gesture.Shake, () => { - let tool = Math.randomInt(3) + let tool = Math.randomRange(0, 3) if (tool == 0) { basic.showLeds(` # # # # # @@ -94,7 +94,7 @@ Place a ``||basic:show leds||`` block under the else if and draw a **rock** imag ```blocks let tool = 0; input.onGesture(Gesture.Shake, () => { - let tool = Math.randomInt(3) + let tool = Math.randomRange(0, 3) if (tool == 0) { basic.showLeds(` # # # # # @@ -125,7 +125,7 @@ That's why you can use an ``else`` instead of an ``else if``. ```blocks let tool = 0; input.onGesture(Gesture.Shake, () => { - let tool = Math.randomInt(3) + let tool = Math.randomRange(0, 3) if (tool == 0) { basic.showLeds(` # # # # # diff --git a/libs/core/helpers.ts b/libs/core/helpers.ts index e3bd1424..8e06cca7 100644 --- a/libs/core/helpers.ts +++ b/libs/core/helpers.ts @@ -12,12 +12,6 @@ namespace Math { //% blockId=logic_random block="pick random true or false" //% help=math/random-boolean weight=0 export function randomBoolean(): boolean { - return true; - //return Math.floor(Math.random() * 2) == 1; - } - - export function randomInt(max: number): number { - return max; - //return Math.floor(Math.random() * max); + return Math.floor(Math.randomRange(0, 1) * 2) == 1; } } \ No newline at end of file