Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion source/MicroBitDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,21 @@ void MicroBitDevice::seedRandom()
{
uint32_t r = 0xBBC5EED;

if(!ble_running())
if (ble_running())
{
#ifdef SOFTDEVICE_PRESENT
// If Bluetooth is enabled, we need to go through the Nordic software to safely do this.
uint8_t available_bytes = 0;
while (available_bytes < 4)
sd_rand_application_bytes_available_get(&available_bytes);

uint32_t random_value = 0;
uint32_t result = sd_rand_application_vector_get((uint8_t*)&random_value, sizeof(random_value));
if (result == NRF_SUCCESS)
r = random_value;
#endif
}
else
{
// Start the Random number generator. No need to leave it running... I hope. :-)
NRF_RNG->TASKS_START = 1;
Expand Down
Loading