barebox/lib/random.c
Sascha Hauer 50f75a1a0e UBI: reimport UBI from Linux v3.10
This is a fresh UBI import from Linux v3.10

This is done mainly to get fastmap support.

This was tested with the i.MX nand driver, the MXS nand driver and
on CFI NOR flash.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2013-07-25 10:24:16 +02:00

29 lines
456 B
C

#include <common.h>
#include <stdlib.h>
static unsigned int random_seed;
#if RAND_MAX > 32767
#error this rand implementation is for RAND_MAX < 32678 only.
#endif
unsigned int rand(void)
{
random_seed = random_seed * 1103515245 + 12345;
return (random_seed / 65536) % (RAND_MAX + 1);
}
void srand(unsigned int seed)
{
random_seed = seed;
}
void get_random_bytes(void *_buf, int len)
{
char *buf = _buf;
while (len--)
*buf++ = rand() % 256;
}