Closed smvilar closed 9 years ago
also smaller seeds seem to cause poor generation, not sure if this is intentional, I note when you set it up in the helper class you have to multiply the seed to a much larger number.
Nico
On Tue, Jul 28, 2015 at 7:55 PM, Santiago V. notifications@github.com wrote:
I ran into this by mistake, but I think it's worth fixing it by adding a Math.abs(seed) to the constructor or something like that.
— Reply to this email directly or view it on GitHub https://github.com/underscorediscovery/luxe/issues/298.
@smvilar which platform were you testing on and do you construct with your own seed or use Luxe.utils.random
@underscorediscovery web, with my own seed
that didn't sound weird at all
HAHA, thanks for the info @smvilar, I'd be curious what you're using for the seed, as it's possible that it wraps around from being too big.
Yes, I think that a big number may be the case. I'm using a string converted to an int with a crc32 hash (btw if you know a better way to do this please tell me). That's because I want all the "random" generated stuff in the game to be dependent on the username.
So yeah maybe it was a really big number, but I think it was a negative seed because I added Math.abs(seed)
and it solved it.
I think that a negative seed is quite possible and will return negative results but I am mainly considering whether or not forcing that value to be mutated is a good idea. For example if you generate the seed and print it and then print the random seed they will differ, and this will cause headaches if you don't understand why.
The other alternative is an assertion on negative seeds, but I also see that as invasive.
For the string conversion, you could try Luxe.utils.hash('username') (which uses djb2 currently, so that may not be ideal) but it returns unsigned value meaning it can't be negative and will fit in the same size as the seed should without wrapping. I don't think it's better per se, just wanted to note there are some options for unique id's and hashes there that might suit something.
I find it really annoying that it gave me negative values, since I was expecting a number to use it as an array index, and when it returned a negative value (outside the expected range) it generated an out of bounds exception! It wasn't clear why the game was failing at first glance, and I had to debug it for a while until I discovered the negative seed.
I ran into this by mistake, but I think it's worth fixing it by adding a
Math.abs(seed)
to the constructor or something like that.