<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>non-random behaviour</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/444/non-random-behaviour</link><description>Hi, 
 I&amp;#39;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-&amp;gt;TASKS_START</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 30 Dec 2013 23:02:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/444/non-random-behaviour" /><item><title>RE: non-random behaviour</title><link>https://devzone.nordicsemi.com/thread/2302?ContentTypeID=1</link><pubDate>Mon, 30 Dec 2013 23:02:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:288965bc-59e1-49ea-b080-e4d4f8de0825</guid><dc:creator>Jim</dc:creator><description>&lt;p&gt;It appears that this only works after the ble stack is initialized, and doesn&amp;#39;t interfere with the BLE operation.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: non-random behaviour</title><link>https://devzone.nordicsemi.com/thread/2301?ContentTypeID=1</link><pubDate>Mon, 30 Dec 2013 22:46:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:467acc20-036b-4ff0-be42-e16bee784f7c</guid><dc:creator>Jim</dc:creator><description>&lt;p&gt;You&amp;#39;re right, this doesn&amp;#39;t work! :-)&lt;/p&gt;
&lt;p&gt;Using TØs code I get the same number every time.  I&amp;#39;m calling this code at the very beginning of my main() so it&amp;#39;s before the SD gets initialized.&lt;/p&gt;
&lt;p&gt;When is the right time to use this?  I don&amp;#39;t want to screw up the SD.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: non-random behaviour</title><link>https://devzone.nordicsemi.com/thread/2300?ContentTypeID=1</link><pubDate>Thu, 19 Sep 2013 13:09:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1560e9c-e52f-43b9-a654-d67013aaa4d4</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;You could try something like this to read out a random buffer of any size:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void get_rnd_buf(uint8_t *buf, uint8_t len)
{
    uint8_t bytes_available;
    do
    {
        sd_rand_application_bytes_available_get(&amp;amp;bytes_available);
        if(bytes_available &amp;gt;= 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 &amp;gt; 0);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;NB! NOT TESTED, USE AT OWN RISK ;)&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: non-random behaviour</title><link>https://devzone.nordicsemi.com/thread/2299?ContentTypeID=1</link><pubDate>Wed, 18 Sep 2013 13:05:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a236b7f-7027-4869-ab91-0dd14e683a80</guid><dc:creator>Alan Ambrose</dc:creator><description>&lt;p&gt;Are there any docs or examples available beyond these signatures?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
uint32_t sd_rand_application_pool_capacity_get  ( uint8_t *  p_pool_capacity )  

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Parameters
[out] p_pool_capacity The capacity of the pool.
Returns NRF_SUCCESS&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
uint32_t sd_rand_application_bytes_available_get  ( uint8_t *  p_bytes_available )  

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Parameters
[out] p_bytes_available The number of bytes currently available in the pool.
Returns NRF_SUCCESS&lt;/p&gt;
&lt;p&gt;Alan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: non-random behaviour</title><link>https://devzone.nordicsemi.com/thread/2296?ContentTypeID=1</link><pubDate>Thu, 12 Sep 2013 02:49:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3a112d34-b149-4b79-9a40-de6b562ae304</guid><dc:creator>Bastiaan</dc:creator><description>&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: non-random behaviour</title><link>https://devzone.nordicsemi.com/thread/2297?ContentTypeID=1</link><pubDate>Thu, 12 Sep 2013 02:49:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3efb6018-860f-4947-bf8d-62dedb7607ae</guid><dc:creator>Guest</dc:creator><description>&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: non-random behaviour</title><link>https://devzone.nordicsemi.com/thread/2298?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2013 07:48:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d7963fd-08d1-4a50-8447-ba352e6e542c</guid><dc:creator>Guest</dc:creator><description>&lt;p&gt;The softdevice uses the RNG. So when you try to write any register of the RNG when the softdevice is enabled the device wil go into hardfault.&lt;/p&gt;
&lt;p&gt;You need to use the functionality provided by the soc libary:
&lt;a target="_blank" href="https://devzone.nordicsemi.com/documentation/nrf51/4.3.0/html/group__nrf__soc__api.html#ga7e372c86c718f517174c53a611792489" rel="nofollow"&gt;https://devzone.nordicsemi.com/documentation/nrf51/4.3.0/html/group__nrf__soc__api.html#ga7e372c86c718f517174c53a611792489&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I do not know how these work exaclty, but it is the only way to use the RNG when softdevice is enabled.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: non-random behaviour</title><link>https://devzone.nordicsemi.com/thread/2295?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2013 07:48:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:21376395-476f-4658-8049-d09d02d6f457</guid><dc:creator>Bastiaan</dc:creator><description>&lt;p&gt;The softdevice uses the RNG. So when you try to write any register of the RNG when the softdevice is enabled the device wil go into hardfault.&lt;/p&gt;
&lt;p&gt;You need to use the functionality provided by the soc libary:
&lt;a target="_blank" href="https://devzone.nordicsemi.com/documentation/nrf51/4.3.0/html/group__nrf__soc__api.html#ga7e372c86c718f517174c53a611792489" rel="nofollow"&gt;https://devzone.nordicsemi.com/documentation/nrf51/4.3.0/html/group__nrf__soc__api.html#ga7e372c86c718f517174c53a611792489&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I do not know how these work exaclty, but it is the only way to use the RNG when softdevice is enabled.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: non-random behaviour</title><link>https://devzone.nordicsemi.com/thread/2294?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2013 05:51:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7836ab17-b1f3-4863-8571-34be386a91fe</guid><dc:creator>Stanley Cheng</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I can get a random number by using RNG with following code.&lt;/p&gt;
&lt;p&gt;// sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, softdevice_assertion_handler);
for (;;)
{
NRF_RNG-&amp;gt;EVENTS_VALRDY = 0;
NRF_RNG-&amp;gt;TASKS_START = 1;
while(NRF_RNG-&amp;gt;EVENTS_VALRDY==0) {}
u8_randNum = (u8)NRF_RNG-&amp;gt;VALUE;
}&lt;/p&gt;
&lt;p&gt;However, It seems stuck with NRF_RNG register accessing when sd_softdevice_enable is called in the program beginning.&lt;/p&gt;
&lt;p&gt;Thanks for help.
Stanley&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: non-random behaviour</title><link>https://devzone.nordicsemi.com/thread/2293?ContentTypeID=1</link><pubDate>Tue, 10 Sep 2013 14:16:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6500f1b9-aafb-43f1-87b6-39c14cbf723f</guid><dc:creator>Martijn</dc:creator><description>&lt;p&gt;NRF_RNG-&amp;gt;EVENTS_VALRDY  is a hardware event. It Will be set to non zero when the random generator had finished generating a number.&lt;/p&gt;
&lt;p&gt;Note that the current version of the hardware has some faults. There will be no new number generated after the first. You meed to stop the generator and restart it again to get a new random number. See the PAN-028 document.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>