<?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>Random number generator example</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/100155/random-number-generator-example</link><description>I&amp;#39;m looking for an example program for a random number generator on a nRF52840-DK. 
 I want to now what #include statements I need, what initialization functions I need to call, the function to retrieve a random number, and any modifications I need to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 14 Oct 2024 16:59:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/100155/random-number-generator-example" /><item><title>RE: Random number generator example</title><link>https://devzone.nordicsemi.com/thread/506188?ContentTypeID=1</link><pubDate>Mon, 14 Oct 2024 16:59:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ecd58b1-cde5-4f2f-9637-78adf4955577</guid><dc:creator>grzegorz</dc:creator><description>&lt;p&gt;Zephyr doesn&amp;#39;t matter here, it&amp;#39;s always possible. Just use modulo.&lt;/p&gt;
&lt;p&gt;int r = sys_rand32_get() % 100;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random number generator example</title><link>https://devzone.nordicsemi.com/thread/490674?ContentTypeID=1</link><pubDate>Tue, 25 Jun 2024 13:43:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df7afff4-5615-47a4-8125-66d1ab0632a6</guid><dc:creator>mej7000</dc:creator><description>&lt;p&gt;This is exactly what I was looking for... But, I would like to limit the range of the random number generated to 0-100.&amp;nbsp; Such as:&amp;nbsp;&amp;nbsp;&lt;span&gt;random(min, max). Is that possible with Zephyr? I&amp;#39;m not seeing it.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random number generator example</title><link>https://devzone.nordicsemi.com/thread/427615?ContentTypeID=1</link><pubDate>Thu, 25 May 2023 20:54:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b415d71-a9ee-43f5-948d-a2ac8d971ebe</guid><dc:creator>Jerry Easley</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;Excellent! Thank you so much!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Random number generator example</title><link>https://devzone.nordicsemi.com/thread/427611?ContentTypeID=1</link><pubDate>Thu, 25 May 2023 18:43:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2246ddf4-0a6f-41aa-bd69-1507a5894f1f</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can use the random API subsystem (&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/services/crypto/random/index.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/services/crypto/random/index.html&lt;/a&gt;) for this. To use the API, you simply include the&amp;nbsp;&amp;lt;zephyr/random/rand32.h&amp;gt; header and add &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/kconfig/index.html#CONFIG_ENTROPY_GENERATOR"&gt;CONFIG_ENTROPY_GENERATOR&lt;/a&gt;=y to your prj.conf.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here is a minimal example I made based on the Zephyr &amp;#39;Hello World&amp;#39; sample:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/hello_5F00_world_5F00_rand.zip"&gt;devzone.nordicsemi.com/.../hello_5F00_world_5F00_rand.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Note:&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/cryptocell.html?cp=5_0_0_5_5"&gt;CRYPTOCELL — ARM TrustZone CryptoCell 310&lt;/a&gt;&amp;nbsp;is the default entropy source if your build target is &amp;#39;nrf52840dk_nrf52840&amp;#39;.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>