-
-
Save perenstrom/f592665078d340a80bc56a11ea4cbdfd to your computer and use it in GitHub Desktop.
Medium: AB-testing 2
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
export const randomFromSeed = (seed) => { | |
if (!seed) { | |
return -1; | |
} | |
let newSeed = 0; | |
for (let i = 0; i < seed.length; i += 1) { | |
newSeed += seed.charCodeAt(i) * Math.pow(10, i); | |
} | |
const x = Math.sin(newSeed) * 10000; | |
return x - Math.floor(x); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment