<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>rng | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/rng/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Thu, 14 May 2020 09:23:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>rng | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>A fast random number generator in C</title>
		<link>https://learncgames.com/a-fast-random-number-generator-in-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=a-fast-random-number-generator-in-c</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 23 May 2020 23:00:43 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[rng]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=667</guid>

					<description><![CDATA[<p>If you are using RNGs (Random Number Generators) for cryptography then you need one that has been validated for sufficient randomness. For example the libsodium library. But if you want a fast one for general purpose use, then xoshiro256++ is a fast one.  It&#8217;s actually that short that I can list it here. Just call [&#8230;]</p>
The post <a href="https://learncgames.com/a-fast-random-number-generator-in-c/">A fast random number generator in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:714,&quot;href&quot;:&quot;https:\/\/github.com\/jedisct1\/libsodium&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260130114717\/https:\/\/github.com\/jedisct1\/libsodium&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 17:44:34&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-10 16:41:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-13 20:08:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-17 19:14:48&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-21 02:11:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-25 10:18:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-03 08:42:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-07 17:01:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-11 17:17:40&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-15 17:04:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-18 22:30:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-22 15:34:32&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-26 10:30:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-31 19:04:08&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-05 12:22:53&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-09 15:29:35&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-12 23:24:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-17 16:34:08&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-21 17:26:31&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-21 17:26:31&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:715,&quot;href&quot;:&quot;http:\/\/prng.di.unimi.it\/xoshiro256plusplus.c&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260108074243\/https:\/\/prng.di.unimi.it\/xoshiro256plusplus.c&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 17:44:42&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-02-12 03:14:53&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-02-15 06:05:17&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-02-18 23:58:03&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-22 11:33:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-25 22:52:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-03 08:42:08&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-08 06:55:56&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-11 17:17:44&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-16 02:08:00&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-03-21 14:57:42&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-26 10:30:15&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-01 03:16:45&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-09 15:29:40&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-12 23:24:36&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-17 16:34:15&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-21 17:26:37&quot;,&quot;http_code&quot;:503}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-21 17:26:37&quot;,&quot;http_code&quot;:503},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img fetchpriority="high" decoding="async" class="alignleft size-medium wp-image-668" src="https://learncgames.com/wp-content/uploads/2020/05/binary-1254484_640-300x187.png" alt="Random numbers" width="300" height="187" srcset="https://learncgames.com/wp-content/uploads/2020/05/binary-1254484_640-300x187.png 300w, https://learncgames.com/wp-content/uploads/2020/05/binary-1254484_640.png 640w" sizes="(max-width: 300px) 100vw, 300px" />If you are using RNGs (Random Number Generators) for cryptography then you need one that has been validated for sufficient randomness. For example the <a title="Link to libsodium on Github" href="https://github.com/jedisct1/libsodium" target="_blank" rel="nofollow noopener noreferrer">libsodium</a> library.</p>
<p>But if you want a fast one for general purpose use, then <a title="Link to xorshirom256++" href="http://prng.di.unimi.it/xoshiro256plusplus.c" target="_blank" rel="noopener noreferrer">xoshiro256++</a> is a fast one.  It&#8217;s actually that short that I can list it here. Just call next() and mod it (%) with the highest value+1. E.G. for a dice roll,</p>
<pre><code class="language-c" data-line="">int diceroll= (next() %6) +1;
</code></pre>
<p>This algorithm is very fast, typically on the order of nano-seconds 10<sup>-9</sup> seconds.</p>
<pre><code class="language-c" data-line="">#include &lt;stdint.h&gt;
uint64_t rngstate[4];

static inline uint64_t rotl(const uint64_t x, int k) {
    return (x &lt;&lt; k) | (x &gt;&gt; (64 - k));
}

// Returns a Uint64 random number
uint64_t next(void) {
    const uint64_t result = rotl(rngstate[0] + rngstate[3], 23) + rngstate[0];
    const uint64_t t = rngstate[1] &lt;&lt; 17;
    rngstate[2] ^= rngstate[0];
    rngstate[3] ^= rngstate[1];
    rngstate[1] ^= rngstate[2];
    rngstate[0] ^= rngstate[3];
    rngstate[2] ^= t;
    rngstate[3] = rotl(rngstate[3], 45);
    return result;
}</code></pre>The post <a href="https://learncgames.com/a-fast-random-number-generator-in-c/">A fast random number generator in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">667</post-id>	</item>
		<item>
		<title>Fast Random Number Generators in C</title>
		<link>https://learncgames.com/fast-random-number-generators-in-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fast-random-number-generators-in-c</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 29 Feb 2020 19:59:37 +0000</pubDate>
				<category><![CDATA[Game]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[rng]]></category>
		<category><![CDATA[romu]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=17</guid>

					<description><![CDATA[<p>Today I found out about Romu (Rotate and Multiply) random number generators. Typically I&#8217;ve been using srand() in my asteroids game, so this is well worth a look.  Their code page lists functions, so they should be easy to plugin.</p>
The post <a href="https://learncgames.com/fast-random-number-generators-in-c/">Fast Random Number Generators in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:835,&quot;href&quot;:&quot;http:\/\/www.romu-random.org&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260206195901\/https:\/\/www.romu-random.org\/&quot;,&quot;redirect_href&quot;:&quot;https:\/\/www.romu-random.org\/&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-14 10:21:14&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-18 23:37:56&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-02 23:26:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-09 20:10:14&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-17 09:52:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-28 17:56:18&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-13 18:40:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-22 16:17:48&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-22 16:17:48&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:836,&quot;href&quot;:&quot;http:\/\/www.romu-random.org\/code.c&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20250521132917\/https:\/\/romu-random.org\/code.c&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 19:58:20&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-14 10:21:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-18 23:37:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-02 23:26:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-09 20:10:16&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-03-17 09:52:44&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-28 17:56:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-13 18:40:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-22 16:17:42&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-22 16:17:42&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img decoding="async" class="alignnone size-medium wp-image-19" src="https://learncgames.com/wp-content/uploads/2020/02/romu-300x165.png" alt="" width="300" height="165" srcset="https://learncgames.com/wp-content/uploads/2020/02/romu-300x165.png 300w, https://learncgames.com/wp-content/uploads/2020/02/romu-768x422.png 768w, https://learncgames.com/wp-content/uploads/2020/02/romu.png 847w" sizes="(max-width: 300px) 100vw, 300px" />Today I found out about <a href="http://www.romu-random.org/" target="_blank" rel="noopener noreferrer">Romu</a> (Rotate and Multiply) random number generators. Typically I&#8217;ve been using srand() in my asteroids game, so this is well worth a look.  Their <a href="http://www.romu-random.org/code.c">code page</a> lists functions, so they should be easy to plugin.</p>The post <a href="https://learncgames.com/fast-random-number-generators-in-c/">Fast Random Number Generators in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">17</post-id>	</item>
	</channel>
</rss>
