Git Product home page Git Product logo

Comments (8)

josephg avatar josephg commented on June 27, 2024

Sorry, I'm not sure I understand what you're trying to do.

On Friday, 26 February 2016, Andrew Mast [email protected] wrote:

How do I make the seed work for 2^32 or 2^64 numbers?


Reply to this email directly or view it on GitHub
#15.

from noisejs.

AndrewMast avatar AndrewMast commented on June 27, 2024

How do I change this function to work for 2^32 or 2^64 numbers?

  // This isn't a very good seeding function, but it works ok. It supports 2^16
  // different seed values. Write something better if you need more seeds.
  module.seed = function(seed) {
    if(seed > 0 && seed < 1) {
      // Scale the seed out
      seed *= 65536;
    }

    seed = Math.floor(seed);
    if(seed < 256) {
      seed |= seed << 8;
    }

    for(var i = 0; i < 256; i++) {
      var v;
      if (i & 1) {
        v = p[i] ^ (seed & 255);
      } else {
        v = p[i] ^ ((seed>>8) & 255);
      }

      perm[i] = perm[i + 256] = v;
      gradP[i] = gradP[i + 256] = grad3[v % 12];
    }
  };

from noisejs.

josephg avatar josephg commented on June 27, 2024

Why do you want that? Do you simply want more variety in the output?

from noisejs.

AndrewMast avatar AndrewMast commented on June 27, 2024

I want to be able use this:

String.prototype.hashCode = function() {
  var hash = 0, i, chr, len;
  if (this.length === 0) return hash;
  for (i = 0, len = this.length; i < len; i++) {
    chr   = this.charCodeAt(i);
    hash  = ((hash << 5) - hash) + chr;
    hash |= 0; // Convert to 32bit integer
  }
  return hash;
};

from noisejs.

AndrewMast avatar AndrewMast commented on June 27, 2024

So basically I want to know what to do with the module.seed to make it work with 2^32 numbers (So I can use noise.seed("seed".hashCode());)

from noisejs.

Squarific avatar Squarific commented on June 27, 2024

You can take your 2^32 number and divide it by 2^32 then use that.

from noisejs.

AndrewMast avatar AndrewMast commented on June 27, 2024

With this?

String.prototype.hashCode = function() {
  var hash = 0, i, chr, len;
  if (this.length === 0) return hash;
  for (i = 0, len = this.length; i < len; i++) {
    chr   = this.charCodeAt(i);
    hash  = ((hash << 5) - hash) + chr;
    hash |= 0; // Convert to 32bit integer
  }
  return hash / Math.pow(2, 32);
};

from noisejs.

Squarific avatar Squarific commented on June 27, 2024

This should work yes.

from noisejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.