Added RNG utility functions.
Intentionally did not import it in common.sun.
This commit is contained in:
parent
50348a9b47
commit
ca8f59dea2
1 changed files with 18 additions and 0 deletions
18
stdlib/random.sun
Normal file
18
stdlib/random.sun
Normal file
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in a new issue