We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bd446c4 commit e39ab00Copy full SHA for e39ab00
source/MicroBitDevice.cpp
@@ -68,7 +68,19 @@ void MicroBitDevice::seedRandom()
68
{
69
uint32_t r = 0xBBC5EED;
70
71
- if(!ble_running())
+ if (ble_running())
72
+ {
73
+ // If Bluetooth is enabled, we need to go through the Nordic software to safely do this.
74
+ uint8_t available_bytes = 0;
75
+ while (available_bytes < 4)
76
+ sd_rand_application_bytes_available_get(&available_bytes);
77
+
78
+ uint32_t random_value = 0;
79
+ uint32_t result = sd_rand_application_vector_get((uint8_t*)&random_value, sizeof(random_value));
80
+ if (result == NRF_SUCCESS)
81
+ r = random_value;
82
+ }
83
+ else
84
85
// Start the Random number generator. No need to leave it running... I hope. :-)
86
NRF_RNG->TASKS_START = 1;
0 commit comments