Created
July 29, 2016 11:29
-
-
Save mloc/d69c39ef8a3b5f77d7a872f6ed63b360 to your computer and use it in GitHub Desktop.
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
/datum/softrng | |
var/x | |
var/y | |
/datum/softrng/New(seed = world.timeofday) | |
x = round(seed) % 65536 | |
y = x | |
// xorshift16, Marsaglia2003: https://www.jstatsoft.org/article/view/v008i14 | |
/datum/softrng/proc/rand16() | |
var/t = x ^ (y << 5) | |
x = y | |
y = (y ^ (y >> 1)) ^ (t ^ (t >> 3)) | |
return y | |
/datum/softrng/proc/randfloat() | |
return rand16() / 65535 | |
/datum/softrng/proc/randint(lower, upper) | |
return round(randfloat() * (upper - lower + 1) + lower) | |
/datum/softrng/proc/picklist(list/l) | |
return l[randint(1, l.len)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment