klib: add rand()
This commit is contained in:
parent
ebd84e651e
commit
00093b3867
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue