Change docs to randomInt
This commit is contained in:
		@@ -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.random(5), Math.random(5))
 | 
			
		||||
led.plot(Math.randomInt(5), Math.randomInt(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.random(5), Math.random(5))
 | 
			
		||||
    led.plot(Math.randomInt(5), Math.randomInt(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.random(5), Math.random(5))
 | 
			
		||||
    led.plot(Math.randomInt(5), Math.randomInt(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.random(5), Math.random(5))
 | 
			
		||||
            led.plot(Math.randomInt(5), Math.randomInt(5))
 | 
			
		||||
        }
 | 
			
		||||
        basic.pause(1000)
 | 
			
		||||
        basic.clearScreen()
 | 
			
		||||
 
 | 
			
		||||
@@ -62,7 +62,7 @@ let column = 0
 | 
			
		||||
let index = 0
 | 
			
		||||
input.onButtonPressed(Button.AB, () => {
 | 
			
		||||
    for (let index = 0; index <= 4; index++) {
 | 
			
		||||
        list[index] = Math.random(5) + 1
 | 
			
		||||
        list[index] = Math.randomInt(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.random(5) + 1
 | 
			
		||||
        list[index] = Math.randomInt(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.random(5) + 1
 | 
			
		||||
        list[index] = Math.randomInt(5) + 1
 | 
			
		||||
    }
 | 
			
		||||
})
 | 
			
		||||
input.onButtonPressed(Button.B, () => {
 | 
			
		||||
 
 | 
			
		||||
@@ -196,7 +196,7 @@ let player1Turn = false
 | 
			
		||||
let spin = 0
 | 
			
		||||
let delay = 0
 | 
			
		||||
input.onGesture(Gesture.Shake, () => {
 | 
			
		||||
    if (player1Turn == true && Math.random(4) < 3) {
 | 
			
		||||
    if (player1Turn == true && Math.randomInt(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.random(4) < 3) {
 | 
			
		||||
    } else if (Math.randomInt(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.random(4) < 3) {
 | 
			
		||||
    if (player1Turn == true && Math.randomInt(4) < 3) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
})
 | 
			
		||||
 
 | 
			
		||||
@@ -34,7 +34,7 @@ Here's an example mod:
 | 
			
		||||
```blocks
 | 
			
		||||
let hand = 0
 | 
			
		||||
input.onGesture(Gesture.Shake, () => {
 | 
			
		||||
    hand = Math.random(3)
 | 
			
		||||
    hand = Math.randomInt(3)
 | 
			
		||||
    if (hand == 0) {
 | 
			
		||||
        basic.showLeds(`
 | 
			
		||||
            # # # # #
 | 
			
		||||
 
 | 
			
		||||
@@ -59,7 +59,7 @@ input.onButtonPressed(Button.B, () => {
 | 
			
		||||
    basic.showNumber(p2)
 | 
			
		||||
})
 | 
			
		||||
input.onGesture(Gesture.Shake, () => {
 | 
			
		||||
    if (Math.random(p1 + p2 - 1 + 1) + 1 <= p1) {
 | 
			
		||||
    if (Math.randomInt(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.random(8)
 | 
			
		||||
        yes_or_no = Math.randomInt(8)
 | 
			
		||||
    }
 | 
			
		||||
    if (4 > previous_roll) {
 | 
			
		||||
        yes_or_no = Math.random(5)
 | 
			
		||||
        yes_or_no = Math.randomInt(5)
 | 
			
		||||
    }
 | 
			
		||||
    if (2 < yes_or_no) {
 | 
			
		||||
        basic.showString("YES")
 | 
			
		||||
@@ -132,7 +132,7 @@ input.onButtonPressed(Button.AB, () => {
 | 
			
		||||
    }
 | 
			
		||||
})
 | 
			
		||||
input.onGesture(Gesture.Shake, () => {
 | 
			
		||||
    current_roll = Math.random(6)
 | 
			
		||||
    current_roll = Math.randomInt(6)
 | 
			
		||||
    basic.showNumber(current_roll + 1)
 | 
			
		||||
    basic.pause(5000)
 | 
			
		||||
    basic.clearScreen()
 | 
			
		||||
 
 | 
			
		||||
@@ -96,7 +96,7 @@ Steps:
 | 
			
		||||
input.onButtonPressed(Button.A, () => {
 | 
			
		||||
   basic.clearScreen()
 | 
			
		||||
   for (let index = 0; index <= 4; index++) {
 | 
			
		||||
       led.plot(index, Math.random(5))
 | 
			
		||||
       led.plot(index, Math.randomInt(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.random(5))
 | 
			
		||||
       led.plot(index, Math.randomInt(5))
 | 
			
		||||
   }
 | 
			
		||||
})
 | 
			
		||||
input.onButtonPressed(Button.B, () => {
 | 
			
		||||
 
 | 
			
		||||
@@ -150,7 +150,7 @@ basic.forever(() => {
 | 
			
		||||
   } else {
 | 
			
		||||
       game.addScore(1)
 | 
			
		||||
       ball.set(LedSpriteProperty.Y, 0)
 | 
			
		||||
       ball.set(LedSpriteProperty.X, Math.random(5))
 | 
			
		||||
       ball.set(LedSpriteProperty.X, Math.randomInt(5))
 | 
			
		||||
   }
 | 
			
		||||
})
 | 
			
		||||
input.onButtonPressed(Button.A, () => {
 | 
			
		||||
@@ -163,7 +163,7 @@ input.onButtonPressed(Button.B, () => {
 | 
			
		||||
       dodger.change(LedSpriteProperty.X, 1)
 | 
			
		||||
   }
 | 
			
		||||
})
 | 
			
		||||
ball = game.createSprite(Math.random(5), 0)
 | 
			
		||||
ball = game.createSprite(Math.randomInt(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.random(5))
 | 
			
		||||
       ball.set(LedSpriteProperty.X, Math.randomInt(5))
 | 
			
		||||
   }
 | 
			
		||||
})
 | 
			
		||||
input.onButtonPressed(Button.A, () => {
 | 
			
		||||
@@ -195,7 +195,7 @@ input.onButtonPressed(Button.B, () => {
 | 
			
		||||
       dodger.change(LedSpriteProperty.X, 1)
 | 
			
		||||
   }
 | 
			
		||||
})
 | 
			
		||||
ball = game.createSprite(Math.random(5), 0)
 | 
			
		||||
ball = game.createSprite(Math.randomInt(5), 0)
 | 
			
		||||
dodger = game.createSprite(2, 4)
 | 
			
		||||
game.setScore(0)
 | 
			
		||||
```
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user