diff options
author | Alex Auvolat <alex@adnab.me> | 2017-01-14 10:49:28 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2017-01-14 10:49:28 +0100 |
commit | 809d660944cfb515e18bb7f1c1519392b4bccd53 (patch) | |
tree | 6ca443116167b5911daad27550bb0a9a1dd0bce6 /src/lib/libc/stdlib.c | |
parent | c451e6d95b4d0a7ce27fcd97bc94fd3540649b73 (diff) | |
download | kogata-809d660944cfb515e18bb7f1c1519392b4bccd53.tar.gz kogata-809d660944cfb515e18bb7f1c1519392b4bccd53.zip |
More Lua works
Diffstat (limited to 'src/lib/libc/stdlib.c')
-rw-r--r-- | src/lib/libc/stdlib.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/lib/libc/stdlib.c b/src/lib/libc/stdlib.c index 7d08cd1..bc543be 100644 --- a/src/lib/libc/stdlib.c +++ b/src/lib/libc/stdlib.c @@ -3,12 +3,24 @@ #include <kogata/debug.h> +static unsigned long +x=123456789,y=362436069,z=521288629,w=88675123,v=886756453; +/* replace defaults with five random seed values in calling program */ +unsigned long xorshift(void) { + unsigned long t; + t=(x^(x>>7)); x=y; y=z; z=w; w=v; + v=(v^(v<<6))^(t^(t<<13)); + return (y+y+1)*v; +} + int rand(void) { - return 0; // TODO + int i = xorshift(); + if (i < 0) i = -i; + return i; } void srand(unsigned int seed) { - //TODO + x = seed; } void abort() { |