Last active
May 16, 2023 15:38
-
-
Save learosema/38ad7b84fd8aa30c1c1a8fc9e7e58597 to your computer and use it in GitHub Desktop.
eleventy-prng.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// store this file in the _data directory | |
let randomSeed = 1234567; | |
module.exports = { | |
init(seed) { randomSeed = seed; }, | |
random() { | |
randomSeed = randomSeed * 16807 % 2147483647; | |
return randomSeed / 2147483647; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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