Created
June 26, 2019 10:06
-
-
Save y13i/28478459a76aaabfd605decff7de0362 to your computer and use it in GitHub Desktop.
This file contains 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
// todo: use https://github.com/transitive-bullshit/random | |
function rnorm() { | |
return ( | |
Math.sqrt(-2 * Math.log(1 - Math.random())) * | |
Math.cos(2 * Math.PI * Math.random()) | |
); | |
} | |
function textpand(text, length = text.length, sd = 0) { | |
return [...new Array(length)] | |
.map( | |
(_, i) => | |
text[ | |
Math.min( | |
Math.max(Math.floor((text.length * i) / length + rnorm() * sd), 0), | |
text.length - 1 | |
) | |
] | |
) | |
.join(""); | |
} | |
console.log(textpand("unko", 140, 10)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment