Skip to content

Instantly share code, notes, and snippets.

@learosema
Last active May 16, 2023 15:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save learosema/38ad7b84fd8aa30c1c1a8fc9e7e58597 to your computer and use it in GitHub Desktop.
Save learosema/38ad7b84fd8aa30c1c1a8fc9e7e58597 to your computer and use it in GitHub Desktop.
eleventy-prng.js
// store this file in the _data directory
let randomSeed = 1234567;
module.exports = {
init(seed) { randomSeed = seed; },
random() {
randomSeed = randomSeed * 16807 % 2147483647;
return randomSeed / 2147483647;
}
};
Usage example in your templates:
{{ prng.init(341234) }}
{{ prng.random() }}
{{ prng.random() }}
{{ prng.random() }}
{{ prng.random() }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment