Created
August 17, 2011 19:52
-
-
Save landon9720/1152439 to your computer and use it in GitHub Desktop.
rnd7
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 Math._ | |
// random number in range 1 - 5 | |
def rnd5 = (floor(random * 5) + 1).toLong | |
// random bit | |
def rndbit: Long = { | |
val i = rnd5 | |
if (i == 1 || i == 2) 0L | |
else if (i == 3 || i == 4) 1L | |
else rndbit | |
} | |
// random int | |
def rndint = { | |
var i = 0l | |
for (shift <- 0 until 32) { | |
i = i | (rndbit << pow(2, shift).toLong) | |
} | |
i | |
} | |
def ran7 = (rndint % 7) + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment