From 04b119a61ee614d6475edfb3a1e84ce5989f0d55 Mon Sep 17 00:00:00 2001
From: Angus Gratton <gus@projectgus.com>
Date: Thu, 30 Jun 2016 08:18:10 +1000
Subject: [PATCH] Seed libc PRNG from hardware RNG on reset

---
 core/app_main.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/core/app_main.c b/core/app_main.c
index a38fb5f..ebf9e9a 100644
--- a/core/app_main.c
+++ b/core/app_main.c
@@ -21,6 +21,7 @@
 #include "esp/spi_regs.h"
 #include "esp/dport_regs.h"
 #include "esp/wdev_regs.h"
+#include "esp/hwrand.h"
 #include "os_version.h"
 
 #include "espressif/esp_common.h"
@@ -378,6 +379,8 @@ static __attribute__((noinline)) void user_start_phase2(void) {
 
     init_networking(&phy_info, sdk_info.sta_mac_addr);
 
+    srand(hwrand()); /* seed libc rng */
+
     // Call gcc constructor functions
     void (**ctor)(void);
     for ( ctor = &__init_array_start; ctor != &__init_array_end; ++ctor) {