klib: add rand()

This commit is contained in:
yzh 2018-03-18 14:03:00 +08:00
parent ebd84e651e
commit 00093b3867
2 changed files with 12 additions and 0 deletions

View File

@ -2,5 +2,6 @@ NAME = klib
SRCS = src/printk.c \
src/string.c \
src/cpp.c \
src/stdlib.c \
src/io.c
include $(AM_HOME)/Makefile.lib

11
libs/klib/src/stdlib.c Normal file
View File

@ -0,0 +1,11 @@
static unsigned long int next = 1;
int rand(void) {
// RAND_MAX assumed to be 32767
next = next * 1103515245 + 12345;
return (unsigned int)(next/65536) % 32768;
}
void srand(unsigned int seed) {
next = seed;
}