Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@perenstrom
Created June 21, 2019 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perenstrom/f592665078d340a80bc56a11ea4cbdfd to your computer and use it in GitHub Desktop.
Save perenstrom/f592665078d340a80bc56a11ea4cbdfd to your computer and use it in GitHub Desktop.
Medium: AB-testing 2
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