jwagner / simplex-noise.js

A fast simplex noise implementation in Javascript / Typescript.
MIT License
1.61k stars 130 forks source link

error in `/simplex-noise/dist/cjs/simplex-noise.js:460`, `random is not a function` #60

Closed maxfer1221 closed 1 year ago

maxfer1221 commented 1 year ago

Hello, I installed simplex-noise from npm and get the following error upon using it:

.../node_modules/simplex-noise/dist/cjs/simplex-noise.js:460
        const r = i + ~~(random() * (256 - i));
                         ^

TypeError: random is not a function
    at buildPermutationTable (.../node_modules/simplex-noise/dist/cjs/simplex-noise.js:460:26)
    at createNoise3D (.../node_modules/simplex-noise/dist/cjs/simplex-noise.js:164:18)
    ...

Node.js v18.9.1

I've removed my directories from the log. I can't tell if this is an issue on my side (and I am missing the random function) or if this was supposed to be Math.random

Thanks!

jwagner commented 1 year ago

Hey Maximo,

Random is passed in as an argument to buildPermutationTable so it shouldn't be Math.random. It is passed along from the random argument to createNoiseND where it defaults to Math.random.

If I had to guess you are doing something along the lines of createNoise3D('some string') instead of createNoise3D(someRandomFunction).

Can you show me how you are calling simplex-noise to get this error?

maxfer1221 commented 1 year ago

That seemed to be the issue. I wasn't passing a parameter but I am now passing an Alea prng. Thanks for the speedy response!

jwagner commented 1 year ago

Not passing a parameter should not leave random undefined, it should fall back to Math.random. Can you share how you triggered this issue? I'd like to figure out what happenes there. :)