This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Random number generator not so random

Hello DevZone,

SDK 15.0.0, sd132

I'm working on the random number generator peripheral in the nRF52832 and used the peripheral example in my SDK.

When I upload the example code to my devkit I can clearly see that every time the microcontroller boots the numbers differ from each other.

When I want to implement that feature in my project, using the same lines of code and files and settings (I believe) it always seems to give me the same number.

Even across multiple devkits. 

So can anyone tell me what I'm doing wrong here?

Kind regards

Parents Reply
  • After roughly resetting the device 20 times.

    I've added my code below, it is an exact copy from the example except that I only need 6 random numbers instead of the 16 in the example.

    uint8_t                 available;
    uint8_t                 p_buff[6];
    nrf_drv_rng_config_t    config;
    
    config.error_correction = 1;
    config.interrupt_priority = 7;
    
    err_code = nrf_drv_rng_init(&config);
    APP_ERROR_CHECK(err_code);
    
    nrf_drv_rng_bytes_available(&available);
    uint8_t length = MIN(6, available);
    
    err_code = nrf_drv_rng_rand(p_buff, length);
    APP_ERROR_CHECK(err_code);
    
    

Children
Related