diff --git a/stdlib/random.sun b/stdlib/random.sun new file mode 100644 index 0000000..7077902 --- /dev/null +++ b/stdlib/random.sun @@ -0,0 +1,18 @@ +/* ================================================= *\ + * random.sun + * + * ssc standard include utility + * 2016 arookas +\* ================================================= */ + +var __RAND_NEXT; + +function srand(seed) { + __RAND_NEXT = seed; +} + +function rand() { + // this is exactly the formula used in MSL (and, thus, SMS itself) + __RAND_NEXT = (__RAND_NEXT * 1103515245) + 12345; + return (__RAND_NEXT >> 16) & 0x7FFF; +}