File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -68,7 +68,21 @@ void MicroBitDevice::seedRandom()
68
68
{
69
69
uint32_t r = 0xBBC5EED ;
70
70
71
- if (!ble_running ())
71
+ if (ble_running ())
72
+ {
73
+ #ifdef SOFTDEVICE_PRESENT
74
+ // If Bluetooth is enabled, we need to go through the Nordic software to safely do this.
75
+ uint8_t available_bytes = 0 ;
76
+ while (available_bytes < 4 )
77
+ sd_rand_application_bytes_available_get (&available_bytes);
78
+
79
+ uint32_t random_value = 0 ;
80
+ uint32_t result = sd_rand_application_vector_get ((uint8_t *)&random_value, sizeof (random_value));
81
+ if (result == NRF_SUCCESS)
82
+ r = random_value;
83
+ #endif
84
+ }
85
+ else
72
86
{
73
87
// Start the Random number generator. No need to leave it running... I hope. :-)
74
88
NRF_RNG->TASKS_START = 1 ;
You can’t perform that action at this time.
0 commit comments