From 809d660944cfb515e18bb7f1c1519392b4bccd53 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sat, 14 Jan 2017 10:49:28 +0100 Subject: More Lua works --- src/lib/libc/stdlib.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/lib/libc/stdlib.c') 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 +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() { -- cgit v1.2.3