[lib][libc] Use a build-time random value as the seed

Set the seed for the kernel's rand() implementation
to a random value computed at build-time, so we get some
minimal randomness from that RNG.

Bug: 80147716
Change-Id: If5f7915a892b825cb7eba46554f2cb29b8ad2eda
diff --git a/lib/libc/rand.c b/lib/libc/rand.c
index 5bc5d36..74ab2c9 100644
--- a/lib/libc/rand.c
+++ b/lib/libc/rand.c
@@ -23,7 +23,7 @@
 #include <rand.h>
 #include <sys/types.h>
 
-static unsigned int randseed = 12345;
+static unsigned int randseed = KERNEL_LIBC_RANDSEED;
 
 void srand(unsigned int seed)
 {
diff --git a/lib/libc/rules.mk b/lib/libc/rules.mk
index 4165571..ab2baad 100644
--- a/lib/libc/rules.mk
+++ b/lib/libc/rules.mk
@@ -9,6 +9,15 @@
 MODULE_DEPS += lib/heap
 endif
 
+# Generate a random 32-bit seed for the RNG
+KERNEL_LIBC_RANDSEED_HEX := $(shell xxd -l4 -g0 -p /dev/urandom)
+KERNEL_LIBC_RANDSEED := 0x$(KERNEL_LIBC_RANDSEED_HEX)U
+
+MODULE_DEFINES += \
+	KERNEL_LIBC_RANDSEED=$(KERNEL_LIBC_RANDSEED) \
+
+$(info KERNEL_LIBC_RANDSEED = $(KERNEL_LIBC_RANDSEED))
+
 MODULE_SRCS += \
 	$(LOCAL_DIR)/atoi.c \
 	$(LOCAL_DIR)/bsearch.c \