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 ?? or use Random number with NRF51 ?

I've tried to use stdlib's random generate function.

and as usally all of the basic C language's random generate functions does, I've used srand with Seed based random. (And also, used with time(null) argument like this.)

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
srand(time(null);
rand();

and when I coded like this, and when I launch compile, it keeps failure with

._build\nrf51422_xxac.axf: Error: L6218E: Undefined symbol time (referred from main.o). (Why on earth this error occurs??? I've double checked with my time.h header file exists correctly!!)

So I've just give up using rand function and find for Random function.

Seems to be there are two random functions.

RNG function seems to be implement total Random Function just like Linux /dev/random does. (And It needs for NRF51 core's compute power. -But actually I don't need Random that seriously.-)

So I thought there is an alternative solution for random application, and it seems to be softdevice function called sd_rand_application_vector_get.

But Actually I can't find any appropriate document for this function. Is there any document for this function's usage? There are only defines for this function, and no any other explanation about this.

Does this function needs for NRF_RNG_Driver enabled? do I have to include nrf_drv_rng.c to use this function?

Can Anyone help me with usage of this function? Is sd_rand_application has to be initialized to use?

(*ps.

    uint8_t num_rand_bytes_available;
err_code = sd_rand_application_bytes_available_get(&num_rand_bytes_available);
APP_ERROR_CHECK(err_code);
uint8_t rand_number;
if (num_rand_bytes_available > 0)
{
    err_code = sd_rand_application_vector_get(&rand_number, 1);
    APP_ERROR_CHECK(err_code);
}

I've used this code but, It doesn't generate any random number even if I turned the device off and on, or reset button. The first random number fixed and doesn't change at all)

Related