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

Using the random number generator with SDK 15.3

I am trying to use RNG HAL  but I am not sure how to use it and there are (as far as I can tell) no examples. The only thing I need is generating random number. So I'm not using any cryptography, but just need simple random number.

I wrote the code like that:

nrf_rng_task_trigger(NRF_RNG_TASK_SET);
uint8_t value = nrf_rng_random_value_get();

But apparently I'm missing something. I have also added #define RNG_ENABLED 1 to sdk_config.h

Any suggestions what to do?

Thanks.

Parents
  • You can refer to the sdk example (SDK15.3\examples\crypto\nrf_crypto\rng) or SDK15.3\examples\peripheral\rng.

        err_code = nrf_drv_rng_init(NULL);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_INFO("RNG example started.");
    
        while (true)
        {
            uint8_t p_buff[RANDOM_BUFF_SIZE];
            uint8_t length = random_vector_generate(p_buff,RANDOM_BUFF_SIZE);
            NRF_LOG_INFO("Random Vector:");
            NRF_LOG_HEXDUMP_INFO(p_buff, length);
            NRF_LOG_INFO("");
            NRF_LOG_FLUSH();
            nrf_delay_ms(100);
        }

Reply
  • You can refer to the sdk example (SDK15.3\examples\crypto\nrf_crypto\rng) or SDK15.3\examples\peripheral\rng.

        err_code = nrf_drv_rng_init(NULL);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_INFO("RNG example started.");
    
        while (true)
        {
            uint8_t p_buff[RANDOM_BUFF_SIZE];
            uint8_t length = random_vector_generate(p_buff,RANDOM_BUFF_SIZE);
            NRF_LOG_INFO("Random Vector:");
            NRF_LOG_HEXDUMP_INFO(p_buff, length);
            NRF_LOG_INFO("");
            NRF_LOG_FLUSH();
            nrf_delay_ms(100);
        }

Children
Related