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

non-random behaviour

Hi,

I'm trying to generate some time variant values for testing purposes... rand() always returns 1447534768! This is in the proximity app FWIW.

So, I thought I would use the hardware RNG, looking at the example rng_example. Now:


NRF_RNG->TASKS_START=1;
...
NRF_RNG->EVENTS_VALRDY=0;
while(NRF_RNG->EVENTS_VALRDY==0) {}

Just waits for ever?

Alan

Parents
  • You could try something like this to read out a random buffer of any size:

    void get_rnd_buf(uint8_t *buf, uint8_t len)
    {
        uint8_t bytes_available;
        do
        {
            sd_rand_application_bytes_available_get(&bytes_available);
            if(bytes_available >= len)
            {
                sd_rand_application_vector_get(buf, len);
                len = 0;
            }
            else
            {
                sd_rand_application_vector_get(buf, bytes_available); 
                buf += bytes_available;
                len -= bytes_available;            
                sd_app_event_wait();  
            }
        }while(len > 0);
    }
    

    NB! NOT TESTED, USE AT OWN RISK ;)

Reply
  • You could try something like this to read out a random buffer of any size:

    void get_rnd_buf(uint8_t *buf, uint8_t len)
    {
        uint8_t bytes_available;
        do
        {
            sd_rand_application_bytes_available_get(&bytes_available);
            if(bytes_available >= len)
            {
                sd_rand_application_vector_get(buf, len);
                len = 0;
            }
            else
            {
                sd_rand_application_vector_get(buf, bytes_available); 
                buf += bytes_available;
                len -= bytes_available;            
                sd_app_event_wait();  
            }
        }while(len > 0);
    }
    

    NB! NOT TESTED, USE AT OWN RISK ;)

Children
No Data
Related