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

How to use sd_rand_application_vector_get correctly?

  • By default, is it enabling or disabling bias correction? If no, how to enable bias correction?
  • Is the RNG peripheral being left on all the time as a result of us using it, and if so, what is the additional power usage (if any)? Or is it always on already?
  • If the BT stack is also using the generator (I assume it does), is it possible that we could get spurious "NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUE" errors. What is the proper way to handle this error? wait for a while and then retry? or any recommendation.

Here is our pseudo code and we'd like the value uniformly distributed within [0, RANGE). Is the implementation correct?

      uint16_t random = 0;
      sd_rand_application_vector_get((uint8_t*)&random, sizeof(random)));

      uint16_t value = (uint16_t)((float)random / UINT16_MAX * RANGE);

Related