Skip to content

Instantly share code, notes, and snippets.

@cvan
Created April 25, 2018 23:13
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 cvan/2616e33aa84b9221d996622a2c710139 to your computer and use it in GitHub Desktop.
Save cvan/2616e33aa84b9221d996622a2c710139 to your computer and use it in GitHub Desktop.
_getRandomEnvironment = environments => {
const randomEnvironmentIndex = () => Math.floor(Math.random() * environments.length);
let newEnvironmentIndex = randomEnvironmentIndex();
if (this.state && this.state.hasOwnProperty('environmentIndex') && environments.length > 1) {
while (newEnvironmentIndex === this.state.environmentIndex) {
newEnvironmentIndex = randomEnvironmentIndex();
}
}
return newEnvironmentIndex;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment