Last active
August 29, 2015 14:02
-
-
Save duncan/e897d70e0772c42623b5 to your computer and use it in GitHub Desktop.
Fun with Scala to run something only on a smallish percentage of times
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
import scala.util.Random | |
// extracted from a conversation between duncan, chad, and ryan. Don’t take seriously, OK? :) | |
if (scala.util.Random.nextBoolean && scala.util.Random.nextBoolean) {} | |
// OR | |
if((1 to 2).map { _ => scala.util.Random.nextBoolean }.foldLeft(true){(f, v) => f && v }) {} | |
// OR | |
if ((1 to 2).map { _ => scala.util.Random.nextBoolean }.filter(!_).isEmpty) {} | |
// OR | |
if (Random.shuffle((1 to 2).map { _ => Random.nextBoolean }).take(1)) {} | |
// OR FINALLY | |
if (Random.nextInt(2) > 0) {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment