Fix randomInt

This commit is contained in:
Sam El-Husseini
2018-06-01 11:42:38 -07:00
parent b5814709f8
commit 6f148c14e0
61 changed files with 152 additions and 158 deletions

View File

@ -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, lets 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()