meta: move photon/libc to root
This commit is contained in:
31
libc/stdlib/rand.c
Normal file
31
libc/stdlib/rand.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <stddef.h>
|
||||
|
||||
static unsigned int seed = 0;
|
||||
|
||||
void srand(unsigned int _seed)
|
||||
{
|
||||
seed = _seed;
|
||||
}
|
||||
|
||||
int rand(void)
|
||||
{
|
||||
int next = seed;
|
||||
int result;
|
||||
|
||||
next *= 1103515245;
|
||||
next += 12345;
|
||||
result = (int)(next / 65536) % 2048;
|
||||
|
||||
next *= 1103515245;
|
||||
next += 12345;
|
||||
result <<= 10;
|
||||
result ^= (int)(next / 65536) % 1024;
|
||||
|
||||
next *= 1103515245;
|
||||
next += 12345;
|
||||
result <<= 10;
|
||||
result ^= (int)(next / 65536) % 1024;
|
||||
|
||||
seed = next;
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user