Le Twitch 4 Posted July 26, 2014 Report Share Posted July 26, 2014 Math.floor(Math.random() * 2); VS game.rnd.intergerInRange(0, 1); how does "game.rnd" work compared to "Math.random"? which one is preferred? Quote Link to post Share on other sites
lewster32 616 Posted July 26, 2014 Report Share Posted July 26, 2014 game.rnd is an instance of Phaser.RandomDataGenerator which as well as having a lot of nice convenience methods, is also a seeded pseudo-random number generator, meaning you can get repeatable results from it. See this example: http://examples.phaser.io/_site/view_full.html?d=misc&f=repeatable+random+numbers.js&t=repeatable%20random%20numbers (check the developer console to see the output) Yehuda Katz 1 Quote Link to post Share on other sites
Le Twitch 4 Posted July 26, 2014 Author Report Share Posted July 26, 2014 game.rnd is an instance of Phaser.RandomDataGenerator which as well as having a lot of nice convenience methods, is also a seeded pseudo-random number generator, meaning you can get repeatable results from it. See this example: http://examples.phaser.io/_site/view_full.html?d=misc&f=repeatable+random+numbers.js&t=repeatable%20random%20numbers (check the developer console to see the output) interesting. that's pretty cool Quote Link to post Share on other sites
lewster32 616 Posted July 26, 2014 Report Share Posted July 26, 2014 It's great if you want to create 'random' levels which always play out the same, or use 'random' events in multiplayer games and ensure the same things happen on each client. Minecraft's world generation is driven by a seeded PRNG as well, which is why the same level seed will always produce the same virtually infinite world. Quote Link to post Share on other sites
Le Twitch 4 Posted July 26, 2014 Author Report Share Posted July 26, 2014 It's great if you want to create 'random' levels which always play out the same, or use 'random' events in multiplayer games and ensure the same things happen on each client. Minecraft's world generation is driven by a seeded PRNG as well, which is why the same level seed will always produce the same virtually infinite world. such an awesome feature. i'm surprised no one has asked about it yet til now Quote Link to post Share on other sites
hoskope 2 Posted January 24, 2016 Report Share Posted January 24, 2016 Yeah, this is great. I created my own random and find out later that it's inside framework Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.