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

random number generator available always get 0

I have use random number generator in S110, the source code just like:

uint8_t num_rand_bytes_available;
err_code = sd_rand_application_bytes_available_get(&num_rand_bytes_available);
APP_ERROR_CHECK(err_code);
//if there is a randon number available
if(num_rand_bytes_available > 0)
     {
          err_code = sd_rand_application_vector_get(&random_number, 1);
          APP_ERROR_CHECK(err_code);
     }

but I always get 0 of num_rand_bytes_available, and never get any random number. Is there any error when I use the function sd_rand_application_bytes_available_get(), or I missed anything? Thanks.

Parents
  • So you call it one single time very close to the time you've just enabled the softdevice then? So the softdevice probably hasn't had enough time to fill the buffer of random numbers, it takes time to generate them. You need to do something like call it, check if there's a number yet, then delay for a number of milliseconds, call it again etc etc until the point you have enough random numbers (1 in your case). It shouldn't take very long, but you also probably want to ensure you only wait for a certain number of iterations and then fail if there's still none generated.

    And of course the softdevice needs to be active when you're doing this, but I'm sure it is, else you'd be getting errors.

Reply
  • So you call it one single time very close to the time you've just enabled the softdevice then? So the softdevice probably hasn't had enough time to fill the buffer of random numbers, it takes time to generate them. You need to do something like call it, check if there's a number yet, then delay for a number of milliseconds, call it again etc etc until the point you have enough random numbers (1 in your case). It shouldn't take very long, but you also probably want to ensure you only wait for a certain number of iterations and then fail if there's still none generated.

    And of course the softdevice needs to be active when you're doing this, but I'm sure it is, else you'd be getting errors.

Children
No Data
Related