Skip to content

Commit 103e0c8

Browse files
committed
Updated RandomDataGenerator.shuffle to remove several internal calls as min is always zero
1 parent 4431484 commit 103e0c8

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* The Phaser 3 Labs has gained a nifty 'search' feature box thanks to @NemoStein - it allows you to filter out the example categories.
88
* We've added a Mask component, which is available on nearly all Game Objects. It includes the methods `setMask`, `clearMask`, `createBitmapMask` and `createGeometryMask`.
99
* CanvasTexture is a new extension of the Texture object specifically created for when you've got a Canvas element as the backing source of the texture that you wish to draw to programmatically using the Canvas API. This was possible in previous versions, as a Texture object supported having a Canvas as its source, but we've streamlined the process and made it a lot easier for you to refresh the resulting WebGLTexture on the GPU. To create a CanvasTexture just call the `TextureManager.createCanvas` method as before, only this time you'll get a CanvasTexture back which has helper properties and methods. See the complete JSDocs for more details.
10+
* RandomDataGenerator has a new method: `shuffle` which allows you to shuffle an array using the current RNG seed (thanks @wtravO)
1011

1112
### Updates
1213

@@ -37,6 +38,7 @@
3738

3839
* DataManagerPlugin would throw an error on Game.destroy if you had any Scenes in the Scene Manager had not been run. Fix #3596 (thanks @kuoruan)
3940
* If you created a Game with no Scenes defined, and then added one via `Game.scene.add` and passed in a data object, the data would be ignored when starting the Scene.
41+
* Adding a Group with an array of children in the constructor was broken since 3.5. Fix #3612 (thanks @fariazz @samme)
4042

4143
### Examples, Documentation and TypeScript
4244

src/math/random-data-generator/RandomDataGenerator.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,10 @@ var RandomDataGenerator = new Class({
452452
},
453453

454454
/**
455-
* A standard array shuffle implementation using the current seed.
455+
* Shuffles the given array, using the current seed.
456456
*
457457
* @method Phaser.Math.RandomDataGenerator#shuffle
458-
* @since 3.4.0
458+
* @since 3.7.0
459459
*
460460
* @param {array[]} [array] - The array to be shuffled.
461461
*
@@ -464,14 +464,16 @@ var RandomDataGenerator = new Class({
464464
shuffle: function (array)
465465
{
466466
var len = array.length - 1;
467+
467468
for (var i = len; i > 0; i--)
468469
{
469-
var randomIndex = this.integerInRange(0, len);
470+
var randomIndex = Math.floor(this.frac() * (len + 1));
470471
var itemAtIndex = array[randomIndex];
471472

472473
array[randomIndex] = array[i];
473474
array[i] = itemAtIndex;
474475
}
476+
475477
return array;
476478
}
477479

0 commit comments

Comments
 (0)