can not use seeds
marissa999 opened this issue · comments
if you try to use seeds ("var simplex = new SimplexNoise(Math.random);") the script will stop with an error.
Please provide a complete script to reproduce the problem, including the versions that you are using.
The custom random function case is covered by tests and in general works.
@littlesatan any update on this?
I have similar problem, but with custom random functions not working, Math.random
works fine for me.
I'm currently using Phaser.js and this library. Here's example code:
this.rand = new Phaser.RandomDataGenerator(['1234'])
this.simplex = new SimplexNoise(this.rand.normal) // rand.normal() is a function that returns random from 0.0 to 1.0
Gives error: this.frac is not a function
, well the error is useless, because this.frac
is property of Phaser random data generator. There's something going on with class inheritance, the this
variable?
Another example using Chance.js:
this.chance = new Chance('12345');
this.simplex = new SimplexNoise(this.chance.random) // chance.random() is a function that returns random from 0.0 to 1.0
Error: Cannot read property 'random' of undefined
. And also here random
is property of Chance instance
@jwagner i think the problem is solved. like you pointed out in the pull request i misunderstood something. I am really sorry for wasting your time with this.
@DavisMiculis It seems that you should use a PRNG like alea. I hope that I didnt say something wrong now.
@littlesatan Are you suggesting something like:
this.rand = new Phaser.RandomDataGenerator(['1234'])
function my_random() {
return this.rand.normal;
}
this simplex. = new SimplexNoise(my_random);
?
@littlesatan No worries. I appreciate the intent to help, even if it turned out to be a non issue. :)
@DavisMiculis is it possible that you need to bind this.rand.normal?
new SimplexNoise(this.rand.normal.bind(this.rand))
If you just pass this.rand.normal the 'this value' will usually not be bound correctly.
@jwagner oh, I forgot about .bind
, will try later, and comment on result.
I assume this solved your problem. ;)