Skip to content

Commit 0eb23d4

Browse files
committed
RandomDataGenerator.integerInRange(min, max) now includes both min and max within its range (phaserjs#501)
1 parent 52118be commit 0eb23d4

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ Updates:
155155
* Vastly improved visibility API support + pageshow/pagehide + focus/blur. Working across Chrome, IE, Firefox, iOS, Android (also fixes #161)
156156
* Pausing the game will now mute audio and resuming will un-mute, unless it was muted via the game (fixes #439)
157157
* ScaleManager has 2 new events: ScaleManager.enterFullScreen and ScaleManager.leaveFullScreen, so you can respond to fullscreen changes directly.
158+
* RandomDataGenerator.integerInRange(min, max) now includes both `min` and `max` within its range (#501)
158159

159160

160161
Bug Fixes:

examples/wip/rnd.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
3+
4+
function preload() {
5+
6+
7+
}
8+
9+
var sprite;
10+
11+
function create() {
12+
13+
for (var i = 0; i < 1000; i++)
14+
{
15+
var x = game.rnd.integerInRange(10, 20);
16+
17+
if (x === 20)
18+
{
19+
console.log('>>>', x);
20+
}
21+
else if (x === 10)
22+
{
23+
console.log('---', x);
24+
}
25+
else
26+
{
27+
// console.log(x);
28+
}
29+
}
30+
31+
}
32+
33+
function update() {
34+
35+
36+
}
37+
38+
function render() {
39+
40+
}

src/math/RandomDataGenerator.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,15 @@ Phaser.RandomDataGenerator.prototype = {
154154
},
155155

156156
/**
157-
* Returns a random integer between min and max.
157+
* Returns a random integer between and including min and max.
158+
*
158159
* @method Phaser.RandomDataGenerator#integerInRange
159160
* @param {number} min - The minimum value in the range.
160161
* @param {number} max - The maximum value in the range.
161162
* @return {number} A random number between min and max.
162163
*/
163164
integerInRange: function (min, max) {
164-
return Math.floor(this.realInRange(min, max));
165+
return Math.round(this.realInRange(min, max));
165166
},
166167

167168
/**

0 commit comments

Comments
 (0)